MongoDB C # driver 2.0 InsertManyAsync vs BulkWriteAsync

I need to insert many documents into the MongoDB collection using the new C # 2.0 driver. Is the use of collection collection.InsertManyAsync (...). Does BulkWriteAsync (...) matter? (especially about performance).

From what I understand from the MongoDB documentation, pasting with an array of documents should be a voluminous operation under the hood. It's right?

Thank you for your help.

+7
c # mongodb mongodb-.net-driver
source share
1 answer

I found an answer looking at the driver source code: InsertManyAsync uses BulkWriteAsync internally, so using InsertManyAsync is similar to writing:

List<BsonDocument> documents = ... collection.BulkWriteAsync(documents.Select(d => new InsertOneModel<BsonDocument>(d))); 

Obviously, if all operations are inserts, InsertManyAsync should be used.

+9
source share

All Articles