MongoDB
 SQL >> Datenbank >  >> NoSQL >> MongoDB

Mongodb Update Many

  1. Das ist eine typische Eins-zu-viele-Beziehung. Für den User können Sie daher folgendes Schema verwenden:

//User { //_id: ObjectId - this one is unique and inserted to every document by default profile: String, ... } //Activity { description: String, ..., userId: String, // referecing the user _id, e.g. "56a5eccb2258799919dc2c40" } 
  1. Wenn Sie viele Activities auf einmal aktualisieren wollen:

db.activities.update({ userId: '56a5eccb2258799919dc2c40' }, { $set: { description: 'new description' } }, { multi: true //means update all matching docs });