0

As per documentation and code IMongoCollection.InsertMany method in MongoDB C# driver returns nothing. It is strange because e.g. DeleteMany returns DeleteResult info. Even InsertMany as Shell method returns info with Acknowledged etc. (see here).

What is the reason of it? And most important question: how to quickly (without sacrificing performance) get confirmation that InsertMany was correctly done (Acknowledged == true)?

2 Answers 2

1

Cause that's mostly not needed since if the record has been inserted then it will generate and populate the Id value to your object which has been passed for insertion. To see what I mean see this answer MongoDb bulk operation get id

Again, you can use the async version of this method with new driver InsertManyAsync() which returns a Task and as usual you can then check the Task.IsCompleted property to know whether it has completed successfully or not.

Sign up to request clarification or add additional context in comments.

Comments

1

If you look at the API documentation (http://mongodb.github.io/mongo-csharp-driver/2.7/apidocs/html/M_MongoDB_Driver_IMongoCollection_1_InsertMany_1.htm) it seems that the InsertMany is a void method, so it returns nothing.

It's semantic it's exception based: if it completes without errors, so you are sure that all your documents have been inserted successfully

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.