InsertManyAsync vs BulkWriteAsync: in one transaction or not, max rows allowed via MongoDB C# driver

1.7k Views Asked by At

I have questions on InsertManyAsync vs BulkWriteAsync via the NuGet below:

https://www.nuget.org/packages/MongoDB.Driver/2.12.3?_src=template

I want to export 300,000 rows of data around 20 MB, convert them into JSON and import them into Mongo Altas.

My questions:

1 Which operation, InsertManyAsync vs BulkWriteAsync, is transactional, e.g. all or nothing?

2 What is the maximum rows or size allowed for each operation?

The link below or elsewhere don't have the answers:

MongoDB C# driver 2.0 InsertManyAsync vs BulkWriteAsync

https://mongodb.github.io/mongo-csharp-driver/2.12/apidocs/html/M_MongoDB_Driver_IMongoCollection_1_BulkWrite.htm

https://mongodb.github.io/mongo-csharp-driver/2.12/apidocs/html/Overload_MongoDB_Driver_IMongoCollection_1_InsertManyAsync.htm

1

There are 1 best solutions below

5
dododo On

there is no difference between InsertManyAsync and BulkWriteAsync other than BulkWriteAsync can work not only with insert. In other words, InsertManyAsync calls BulkWriteAsync internally.

Is the operation is one transactional operation, e.g. all or nothing?

see transactions. Also, see ordered/unordered option here.

What is the maximum rows or size allowed?

I don't think that there is any limitation other then restriction on the document size which is 16 MB. Pay attention that bulk items can be merged into a single document before sending to the server (that should not be bigger 16 MB in sum) or they should be sent separately one by one. This logic depends on whether you use isOrdered option and whether all items in your batch are with the same bulk type.