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.

  1. firstly storing id, name , picture url of user activity document relation. please tell me if wrong relations , suggest storing relation.

  2. 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.

  1. 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"  }    

  1. if want update many docs activity:

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


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -