为什么MongoDB在重复密钥时发送错误500

时间:2016-02-11 22:24:22

标签: mongodb sails.js

当收到MongoDB的答案时,知道我的错误是重复的密钥,但为什么status = 500 ?,它应该是4 **。 我使用nodejs(sails / express.js)

{   "error": {
    "error": "E_UNKNOWN",
    "status": 500,
    "summary": "Encountered an unexpected error",
    "raw": {
      "name": "MongoError",
      "code": 11000,
      "err": "E11000 duplicate key error index: eReporterDB.users.$name_1 dup key: { : \"codin\" }"
    }   } }

1 个答案:

答案 0 :(得分:0)

the answer is here for nodejs

Operational errors vs. programmer errors

It's helpful to divide all errors into two broad categories:

Operational errors represent run-time problems experienced by correctly-written programs. These are not bugs in the program. In fact, these are usually problems with something else: the system itself (e.g., out of memory or too many open files), the system's configuration (e.g., no route to a remote host), the network (e.g., socket hang-up), or a remote service (e.g., a 500 error, failure to connect, or the like). Examples include:

DataContext

Programmer errors are bugs in the program. These are things that can always be avoided by changing the code. They can never be handled properly (since by definition the code in question is broken). tried to read property of "undefined" called an asynchronous function without a callback passed a "string" where an object was expected passed an object where an IP address string was expected