Node.js から mongoose.js にドキュメントを保存するとエラーが発生します。このコードはしばらくの間問題なく機能していましたが、現在は問題ないように見えるキー値を持つ Javascript オブジェクトで問題が発生しています。
保存されているのは、1 つのメンバーが連想配列であるドキュメントです。簡単にするために、次のように表していSchema.Types.Mixed
ます。
var formatSchema = new mongoose.Schema({
name: {type: String, required: true},
values: {type: mongoose.Schema.Types.Mixed, required: false}
});
1 つのオブジェクトに のようなキーがあると失敗するようになり"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)