node.js - Mongodb Update Many -
i developing using express js , npm module mongodb mongodb database. have 2 collections namely "users" , "activities". there can 1000s of activities of user.
firstly storing id, name , picture url of user activity document relation. please tell me if wrong relations , suggest storing relation.
secondly problem facing when update user's name doesn't updated in activities of user (which is
obvious). want example can update many docs @ once using user id.
please on above. in advance.
- this typical one-to-many relationship. in case of user can have following schema:
//user { //_id: objectid - 1 unique , inserted every document default profile: string, ... } //activity { description: string, ..., userid: string, // referecing user _id, e.g. "56a5eccb2258799919dc2c40" }
- if want update many docs activity:
db.activities.update({ userid: '56a5eccb2258799919dc2c40' }, { $set: { description: 'new description' } }, { multi: true //means update matching docs });
Comments
Post a Comment