32

I am using MongoDB for keeping log data. And my goal is zero dropped log record. Now I am using InsertManyAsync for writing multiple log data. But in MongoDB there is also method like BulkWriteAsync.

What is the difference in performance between InsertMany and BulkWrite? In local writing and writing over network?

Manuel Jordan
  • 15,253
  • 21
  • 95
  • 158
Alisettar Huseynli
  • 944
  • 1
  • 11
  • 24

3 Answers3

52

Ok that's two questions:

InsertMany vs BulkWrite

Using BulkWrite you can do many operations in a single connection to mongoDB. Internally, InsertMany uses BulkWrite, so there's no difference, it's just for convenience.

This question was already solved.

Sync vs Async

When you perform a sync operation, your aplication will wait for MongoDB to finalize the work. With a async operation you can perform many operations at the same time. Server, and client side.

This was already solved too.

Manuel Jordan
  • 15,253
  • 21
  • 95
  • 158
Adrian Lopez
  • 2,601
  • 5
  • 31
  • 48
2

BulkWrite supports a mix of writing operations (inserts, delete and update), while insertMany, as indicated by its name, only inserts documents.

Cabrinha
  • 440
  • 1
  • 3
  • 15
-2

BulkWriteAsync under the cover uses InsertManyAsync for insert operations. The only difference is BulkWriteAsync allows you to perform different operations (insert, update, delete) under one roof. However if you are debating between BulkWriteAsync and InsertManyAsync for inserting bunch of documents, it's recommended to use InsertManyAsync directly.

Saleem
  • 8,728
  • 2
  • 20
  • 34