update only few documents

9 views
Skip to first unread message

David Lavy

unread,
Aug 2, 2015, 7:07:37 AM8/2/15
to Mongoose Node.JS ODM
I am trying to update only 5 first documents and cant find any solution.
the best solution i could find is 

db.collection.find(<condition>).limit(<limit>).forEach(function(doc){db.collection.update({_id:doc._id},{<your update>})})

but this is not good enough for me. I need to update the 5 in bulk immediately and not separate.
Thank you
 

Nathan White

unread,
Aug 2, 2015, 7:38:02 AM8/2/15
to mongoo...@googlegroups.com
You can't.

Update allows you to update the first match (default) or multi which allows bulk update. 

If there is no way for you to create a criteria that only brings back the exact 5 then I would opt for the streaming API.
--
Documentation - http://mongoosejs.com/
Plugins - http://plugins.mongoosejs.com/
Bug Reports - http://github.com/learnboost/mongoose
Production Examples - http://mongoosejs.tumblr.com/
StackOverflow - http://stackoverflow.com/questions/tagged/mongoose
Google Groups - https://groups.google.com/forum/?fromgroups#!forum/mongoose-orm
Twitter - https://twitter.com/mongoosejs
IRC - #mongoosejs
---
You received this message because you are subscribed to the Google Groups "Mongoose Node.JS ODM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongoose-orm...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages