0

I have simple collection like this:

db.people.insert( 
    [
        {
        name:"John",
        sex:"M"
        },
        {
        name:"Susanne",
        sex:"W"
        },
        {
        name:"Kate",
        sex:"W"
        }
])

On the basis of sex field I would like to create other field Sex2:

case
when sex:"M" then sex2:"Man"
when sex:"W" then sex2:"Women"

any tips how I can manage it with .update function?

  • My version of mongodb is 3.2.22 – Gaweł Chiński Apr 14 '20 at 19:42
  • Use the same concept as the marked duplicate where your cursor follows `var cursor = db.people.aggregate([ { "$project": { "sex2": { "$cond": [ { "$eq": ["$sex", "W"] }, "Women", "Men" ] } }} ])` – chridam Apr 14 '20 at 19:54

0 Answers0