mongodb - How do I update a collection using multiple _id's? -
i trying update collection based on multiple _id's.
i recieve _id's in array format via session.get() below:
var selectedid = session.get('selecteditemidset'); console.log("selectedid array contents are: "+selectedid);
the code above ensures selectedid
array exists , yields:
selectedid array contents are: lzjka8s3wynwhakze,ikrbcdutthrwkecuv
the query below:
buylist.find({_id:{ "$in": selectedid} }).fetch();
successfully yeilds 2 objects!
now area having issues with, how update collection these 2 _id's
i have tried below code:
var postedarray = [{postedby: meteor.user()._id }]; buylist.update(_id: selectedid, {$set: {wishlistarray: postedarray} });
...but error message: uncaught error: mongo selector can't array.(…)
any appreciated.
use same selector in update
have done find
+ specify multi: true
option:
buylist.update({ // selector _id: { "$in": selectedid } }, { // modifier $set: { wishlistarray: postedarray } }, { // options multi: true });
note 2 documents updated same modifier.
Comments
Post a Comment