v0.7.0
Menu

#Errors

A failed request gets "ok":false, a code and an error message:

{"code":"invalid","error":"unknown operator $bad","ok":false}

A successful reply has no code. The code says whose mistake it is, so a client does not have to read the message. The messages are English and are not meant to be parsed. There are no numeric codes, and two invalid errors can only be told apart by their message.

#Codes

Code Meaning Examples
bad_request not valid JSON, or not shaped like a request a missing cmd or collection, an unknown command, limit of 0, no database chosen, begin inside a transaction
invalid well formed but cannot be done an unknown operator, a field name with a ., $inc on a string, overlapping update targets, an _id that is not an id, a position past the end of an array, admin as a database name
duplicate an _id that is already taken inserting _id twice
duplicate_key a write refused by a unique index a second document with the same key
unauthorized not allowed not logged in, the wrong token, a role too weak for the request
limit too much a line over 16 MiB, nesting over 100 levels, too many connections, the memory limit, a transaction over its limits, a watcher too far behind
conflict a transaction found that someone else wrote to what it used retry from begin
read_only a write sent to a follower send it to the leader
storage the disk or the log, not the client's doing cannot write or sync the log. The reply does not say more, the cause is printed by the server

#Real examples

{"code":"bad_request","error":"missing text field collection","ok":false}
{"code":"duplicate","error":"duplicate _id","ok":false}
{"code":"duplicate_key","error":"duplicate key in the unique index on v","ok":false}
{"code":"invalid","error":"the updates to a and a overlap","ok":false}
{"code":"invalid","error":"$inc needs a number for v","ok":false}
{"code":"bad_request","error":"no database, send a db with the request or use one first","ok":false}

#What a client can do

Code Reasonable response
bad_request, invalid fix the request. Retrying will not help
duplicate, duplicate_key use another _id or key
unauthorized log in. A wrong token or password closes the connection
limit send less, or wait: for the memory limit, deletes still work and writes are allowed again once the process is under nine tenths of the limit
conflict begin the transaction again
read_only send writes to the leader
storage stop and tell the operator. After a failed write or fsync the server refuses writes until it is restarted, because the data in memory has a change the log does not

#In a transaction

When a write fails inside a transaction, a limit is hit, or a collection is too big to copy, the reply has "aborted":true next to the code, and the transaction is over. A failed read does not end it.

#Not an error reply

Some things close the connection instead of replying: a client that does not log in within 10 seconds, a request that does not arrive whole within 60 seconds, a line that is too long, a watcher that fell behind, and a first line that does not start with { or the binary header. Five wrong logins from one address in a minute lock that address out of logging in for a minute.