Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding Batch Upsert to MongoDB.

Tags:

mongodb

It looks like MonogoDB does not support batch upsert. Is this Correct?

If not, how would you go about adding batch upsert with the existing API which is the most efficient? Does batch upsert even make sense for mongo db?

like image 674
iCode Avatar asked Jan 14 '12 01:01

iCode


Video Answer


1 Answers

If you upgrade to MongoDB 2.6 you can take advantage of the new Bulk operations:

Bulk.find(<query>).upsert().update(<update>);
Bulk.find(<query>).upsert().updateOne(<update>);
Bulk.find(<query>).upsert().replaceOne(<replacement>);    
like image 85
Vlad Mihalcea Avatar answered Sep 24 '22 01:09

Vlad Mihalcea