javascript - Updating MongoDB array from variable array in batch operation? -


i working in node.js , attempting push or pull contents of array mongodb collection. [working] code pull objects array in fieldarray looks this:

for (var i=0; < mylist.length; i++) {     collection.update(         {field:"myvalue"},         {$pull: {fieldarray: mylist[i]}},         function(err, item){...}     ); } 

i'm aware of ability use $push/$each, $addtoset/$each , $pullall don't seem accept values dynamically array (or haven't found indication can). basically, i'd able use function array of 1 item or 1 hundred, using appropriate batch calls.

is there way make such call without having loop through separate call on database each iteration?

you want $pullall. trying iterate over

collection.update(     { "field": "myvalue" },     { "$pullall": { "fieldarray": mylist } } ) 

if doesn't work then array elements not matching structure used in document. make them way.


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -