Reputation: 487
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.
Upvotes: 1
Views: 5785
Reputation: 745
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.
Upvotes: 0
Reputation: 12624
It will raise an exception if an error occurs. http://mongodb.github.io/mongo-csharp-driver/2.2/reference/driver/error_handling/#write-exceptions
Upvotes: 1