MongoDB
 SQL >> Database >  >> NoSQL >> MongoDB

Update condizionali con bulkWrite in MongoDB

Le espressioni di aggregazione non possono scegliere update alternativi in un normale statement di update.

Usa bulkWrite() con più operazioni updateMany.

db.country.bulkWrite([ { "updateMany": { "filter": { "pop": { "$lt": 20000000 } }, "update": { "$set": { "country": "Small Country" } } } }, { "updateMany": { "filter": { "pop": { "$gt": 20000000 } }, "update": { "$set": { "country": "Large Country" } } } } ])