I am developing using express js and npm module mongodb with mongodb as database. I have two collections namely \"users\" and \"activities\". There can be 1000s of activities of
//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"
}
db.activities.update({ userId: '56a5eccb2258799919dc2c40' }, {
$set: {
description: 'new description'
}
},
{
multi: true //means update all matching docs
});
You should store just the _id of the User in the Activity. Then use that to access the User via the Activity (if that's what you want to do).