The MongoException class

Introduction

This covers a bunch of different error conditions that may eventually be
moved to more specific exceptions, but will always extend
MongoException.

The MongoSomething object has not been correctly initialized by its constructor

Code: 0

Probably your Mongo object is not connected to a database server.

zero-length keys are not allowed, did you use $ with double quotes?

Code: 1

You tried to save "" as a key. You generally should not do this. "" can
mess up subobject access and is used by MongoDB internally. However, if
you really want, you can set
mongo.allow_empty_keys
to true in your php.ini file to override this sanity check. If you
override this, it is highly recommended that you set error checking to
strict to avoid string interpolation errors.

'.' not allowed in key: <key>

Code: 2

You attempted to write a key with '.' in it, which is prohibited.

insert too large: <size>, max: <max>

Code: 3

You're attempting to send too much data to the database at once: the
database will only accept inserts up to a certain size (currently 16 MB).

no elements in doc

Code: 4

You're attempting to save a document with no fields.

size of BSON doc is <size> bytes, max <max>MB

Code: 5

You're attempting to save a document that is larger than MongoDB can save.

This error occurs if you attempt to send a non-utf8 string to the
database. All strings going into the database should be UTF8. See php.ini
options for the transition option of quieting this exception.

mutex error: <err>

Code: 13

The driver uses mutexes for synchronizing requests and responses in
multithreaded environments. This is a fairly serious error and may not
have a stack trace. It's unusual and should be reported to maintainers
with any system information and steps to reproduce that you can provide.

index name too long: <len>, max <max> characters

Code: 14

Indexes with names longer than 128 characters cannot be created. If you
get this error, you should use
MongoCollection::ensureIndex()'s "name" option to
create a shorter name for your index.

Class synopsis

User Contributed Notes 1 note

In case of "zero-length keys are not allowed, did you use $ with double quotes?" error, checking the saved data for objects with private/protected variables can solve the problem.

It seems, that the PECL extension currently does not support private/protected variables, thus making their keys empty strings. A simple, yet not allways desirable, solution is to make these variables public.