Christian Kuetbach
Christian Kuetbach

Reputation: 16060

Is there a complete list of mongodb error codes?

To create custom error handling I would like to switch at the errorcode property of a MongoDbException.

Is there any official list of error codes?

I know 112 is a WriteConflict, 16608 means division by 0 and 16610 is a modulo by zero.

error_codes.yml is incomplete and lacks of 16608 and 16610.

Upvotes: 17

Views: 19142

Answers (3)

springuper
springuper

Reputation: 578

There is a list in Mongo official doc website: https://www.mongodb.com/docs/manual/reference/error-codes/

Upvotes: 1

Isko
Isko

Reputation: 121

I found a list here (the same as yours)link. In my case, We launched a lot of test scenarios and then i searched in logs all the possible codes. The ones that i found are :

  • 112 write conflict (when a transaction is failed)
  • 11000 Duplicate Key (when a unique constraint index is violated)
  • 211 or 11600 When mongo is down or i have a bad config

So If we don't have a better solution. All we can do is handling the most redundant cases. The other cases are handled as 500 server error.

Upvotes: 10

D. SM
D. SM

Reputation: 14490

MongoDB server source code is publicly available, if you want to get information about a particular error, or get a list of all errors, going through the source is going to be your best bet.

Per Daemon Painter's comment, there is an open docs ticket to provide a list of error codes.

One challenge with such a list is the server does not guarantee when it will produce a particular error code. Therefore a comprehensive list of error codes either would be not very useful (if it only tells you what error codes exist but not when you would get them) or it would be labor-intensive to maintain.

The drivers generally look for certain error codes in certain situations only (see for example here). They don't have a complete list of error codes.

Upvotes: 2

Related Questions