mardi 14 avril 2020

Conditional update, depending on field matched-Mongodb [duplicate]

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?

Aucun commentaire:

Enregistrer un commentaire