1

I am using mongodbc# driver which includes legacy driver. And using InsertOne() method insert records. But it is void, how do I know if there is error in insertion and what type of exception is thrown.

2 Answers 2

1

It will raise an exception if an error occurs. http://mongodb.github.io/mongo-csharp-driver/2.2/reference/driver/error_handling/#write-exceptions

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

Comments

0

Just use Try Catch

try {
db.products.insertOne(
   { "item": "envelopes", "qty": 100, type: "Self-Sealing" },
   { writeConcern: { w : "majority", wtimeout : 100 } }
);
} catch (e) {
   print (e);
}

it will catch the Exception.

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.