2014년 12월 13일 토요일

best way to do bulk insert/replace?

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?



You are going to want to do an upsert with replacement like this:

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

댓글 없음:

댓글 쓰기