Search code examples
node.jsmongodbnode-mongodb-native

What does an example MongoDB error look like on the NodeJS native driver?


I can't seem to find any examples of MongoDB error objects in their documentation or on the internet.

What does an example MongoDB error object look like? I'd like to "handle" the error and/or reformat it for my own purposes, depending on what the error is.


Solution

  • As of MongoDB 2.4.8 with the mongodb 1.3.23 driver, they look like this:

    {
      "name":"MongoError",
      "err":"E11000 duplicate key error index: test.test.$country_1  dup key: { : \"XYZ\" }",
      "code":11000,
      "n":0,
      "connectionId":10706,
      "ok":1
    }