Error: process.nextTick(function() { throw err; });

Published on Author Code Father

Getting the following error when i run my app.js. Unable to resolve the issue.

/Applications/MAMP/htdocs/simplehacker/simplehacker-us/node_modules/mongodb/lib/utils.js:98
process.nextTick(function() { throw err; });
                          ^
WriteError({"code":11000,"index":0,"errmsg":"E11000 duplicate key error index: instance.instancesmodels.$PublicDnsName_1 dup key: { : \"\" }","op":{"PublicDnsName":"","instanceId":"i-d9ff937a","reservationId":"r-60e814b6","name":"adhoc s1","region":"us-east-1b","status":"stopped","net_io":"","cpu_usage":"","_id":"56a9c6d1e86e8bff040644cb","isInUse":false,"__v":0}})
at Function.MongoError.create....

Ans in the second line: WriteError:

WriteError({
  "code": 11000,
  "index": 0,
  "errmsg": "E11000 duplicate key error index: instance.instancesmodels.$PublicDnsName_1 dup key: { : \"\" }",
  "op": {
    "PublicDnsName": "",
    "instanceId": "i-d9ff937a",
    "reservationId": "r-60e814b6",
    "name": "adhoc s1",
    "region": "us-east-1b",
    "status": "stopped",
    "net_io": "",
    "cpu_usage": "",
    "_id": "56a9c6d1e86e8bff040644cb",
    "isInUse": false,
    "__v": 0
  }
})

This index does not allow the write: instance.instancesmodels.$PublicDnsName_1. It seems that you’re inserting duplicate PublicDnsName (which in your case is an empty string).

You either have to remove the unique flag from the PublicDnsName index, or allow for a sparse index and then leave null values when there’s no name.

Depending on what drivers you use, ORMs, such as mongoose and similar, you can resolve it on the app level or on the database level.

Comments

comments