0

I am using mongodb database. What the MongoDB will return if there any exception while saving,updating or deleting data(or object)?

How to handle exception in MongoDB?

2 Answers 2

3

MongoDB by default (in some drivers) does not enforce a safe mode whereby the database will physically respond to every call you make to say whether or not it was successful.

However in most drivers there is a getLastError() and you can, of course, enforce safe mode on calls using something similar to:

update({},{},{safe:true});

Using both of these methods will allow you to return problems MongoDB might get in handling your operations.

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

2 Comments

Its better to have safe set to true while making Connection itself, instead of passing in every write query.
Presuming the driver supports that, the PHP driver didn't support that pre-1.3, since we have no idea what driver he is using we cannot make assumptions about that functionality being there
2

While making a connection to mongod, set safe to true, for instance here is how it can be done using python driver (pymongo)

from pymongo import Connection
connection = Connection('localhost', 27017, safe = True)

By doing so you will get write acknowledgements, else it would be simple fire and forget.

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.