| 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] |
| Redirection Notice This page should redirect to http://docs.mongodb.org/meta-driver/latest/legacy/error-handling-in-drivers/. |
| From: | MongoDB > Writing Drivers and Tools |
| To: | MongoDB > Old Pages |