best way to do bulk insert/replace?

121 views
Skip to first unread message

Arek Czechowski

unread,
Dec 11, 2014, 11:09:52 AM12/11/14
to mongod...@googlegroups.com
I want to insert multiple documents into mongo, as fast as possible, and each document will have unique _id given by me

If _id is already used I want this document to be replaced with new version - no updates. 

if there isnt a doc with same _id - I want just plain insert

Is there any trick/option to make bulk insert work this way?

Tyler Brock

unread,
Dec 11, 2014, 1:44:09 PM12/11/14
to mongod...@googlegroups.com
You are going to want to do an upsert with replacement like this:

Bulk.find(<query>).upsert().replaceOne(<replacement>);


--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: http://www.mongodb.org/about/support/.
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at http://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/639f3bd9-1d4d-40db-a4cf-64a95db24b87%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages