简体   繁体   中英

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

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, eg 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

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, eg 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM