Edward83
Edward83

Reputation: 6686

MongoDB InsertBatch exceptions

For example I have new sequence of documents to write with _ids: [1, 2, 3, 4, 5, 6, 7]

and already stored collection of documents with _ids: [3,4,7].

I want to store my new sequence with command InsertBatch and do not wanna to check every _id for existing. Ofcourse Mongo will throw exception because of collision and collection will have only part of new sequence: [3,4,7,1,2]

How could I solve this problem?

Upvotes: 0

Views: 447

Answers (1)

dcrosta
dcrosta

Reputation: 26258

If you are using MongoDB 2.0, you can set the continueOnError flag to false to achieve this behavior. See http://www.mongodb.org/display/DOCS/Inserting#Inserting-Bulkinserts for details, and consult the API documentation for your driver to find out how to use this from your application.

Upvotes: 1

Related Questions