[confluence] MongoDB > Error Handling in Mongo Drivers

11 views
Skip to first unread message

nor...@mongodb.onconfluence.com

unread,
Jan 16, 2013, 7:54:00 PM1/16/13
to mongodb...@googlegroups.com

Error Handling in Mongo Drivers

Page edited by Sam Kleinman


Changes (3)

If an error occurs on a query (or getMore operation), Mongo returns an error object instead of user data.
{redirect:http://docs.mongodb.org/meta-driver/latest/legacy/error-handling-in-drivers/}
The error object has a first field guaranteed to have the reserved key {{$err}}. For example:

{code}{ $err : "some error message" }
{code}The {{$err}} value can be of any type but is usually a string.

Drivers typically check for this return code explicitly and take action rather than returning the object to the user. The query results flags include a set bit when $err is returned.
{code}/* db response format

Query or GetMore: // see struct QueryResult
int resultFlags;
int64 cursorID;
int startingFrom;
int nReturned;
list of marshalled JSObjects;

*/

struct QueryResult : public MsgData {
enum {
ResultFlag_CursorNotFound = 1, /* returned, with zero results, when getMore is called but the cursor id is not valid at the server. */
ResultFlag_ErrSet = 2 /* { $err : ... } is being returned */
};
...
};
{code}

h2. See Also

* The [DOCS:Driver and Integration Center] for information about the latest drivers
* The [top page|DOCS:Writing Mongo Drivers] for this section
* The main [Database Internals] page
* The starting point for all [Home]

Full Content

nor...@mongodb.onconfluence.com

unread,
Jan 16, 2013, 7:55:00 PM1/16/13
to mongodb...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages