1

我从 Node.js 将文档保存到 mongoose.js 时出错。这段代码已经运行了一段时间,但它现在导致 Javascript 对象出现问题,其键值看起来很好。

保存的是一个文档,其中一个成员是一个关联数组,为简单起见,它表示为Schema.Types.Mixed

var formatSchema = new mongoose.Schema({
  name: {type: String, required: true},
  values: {type: mongoose.Schema.Types.Mixed, required: false}
});

当一个对象有一个像"0038-". 具体来说,是破折号-导致了问题。如果我取出这些值(用于测试,而不是为了用户满意度),它加载得很好。将它隔离到这里,现在我不知道如何进行。

[
  {
    "name": "INJURYF",
    "values": {
        "0": "No",
        "1": "Yes"
    }
  },
  {
    "name": "RFVF",
    "values": {
        "10050": "Chills",
        "10100": "Fever",
        "10200": "General weakness",
        "10250": "General ill feeling",
        "00323": "Salmonella arthritis",
        "00324": "Salmonella osteomyelitis",
        "0038-": "Other specified salmonella infections",   // PROBLEM STARTS HERE
        "0039-": "Salmonella infection, unspecified",
        "0040-": "Shigella dysenteriae",
        ...
      }
    }, ...
  ]

这是具体的错误信息,

Express
500 TypeError: Cannot call method 'path' of undefined
at getPositionalPath (/myproject/node_modules/mongoose/lib/schema.js:380:22)
at Schema.path (/myproject/node_modules/mongoose/lib/schema.js:199:9)
at Query._getSchema (/myproject/node_modules/mongoose/lib/query.js:1789:27)
at Query._walkUpdatePath (/myproject/node_modules/mongoose/lib/query.js:1721:16)
at Query._walkUpdatePath (/myproject/node_modules/mongoose/lib/query.js:1716:25)
at Query._castUpdate (/myproject/node_modules/mongoose/lib/query.js:1655:23)
at castDoc (/myproject/node_modules/mongoose/lib/query.js:2160:18)
at Query._findAndModify (/myproject/node_modules/mongoose/lib/query.js:2032:17)
at Query.findOneAndUpdate (/myproject/node_modules/mongoose/lib/query.js:1941:15)
at Function.Model.findOneAndUpdate (/myproject/node_modules/mongoose/lib/model.js:1127:16)

Mongoose 位置操作员错误

4

1 回答 1

1

开始了:

这是旧 mongoose 版本的错误 - 请更新到最新版本。

于 2012-10-26T13:48:57.190 回答