我最近升級到5.4的節點和MongoDB 2.1.4驅動程序的節點,我有以下問題:節點/ MongoDB的JSON空數組錯誤
我有一個包含這樣的事情叫做buildings.json文件:
{
"military_base": {
"type": "military",
"level": 0,
"maxLevel": 25,
"upgrade": true,
"targetEnvironment": [],
"timeUntilBuilt": 0,
"costCoef": 0.4,
"requiredResearches": [
"foo#4",
"bar#1"
],
"requiredResources": [
"cash",
"metal",
"palladium"
],
"inProgress": 0,
"queue": []
},
"aqua_center": {
"type": "industrial",
"level": 0,
"maxLevel": 25,
"upgrade": true,
"targetEnvironment": [
"ocean",
"snowy"
],
"timeUntilBuilt": 0,
"costCoef": 0.7,
"requiredResearches": [
"lorem#10",
"ipsum#3"
],
"requiredResources": [
"cash",
"cristal"
],
"inProgress": 0,
"queue": []
}
}
現在,我想這個文件插入到數據庫蒙哥:
let buildings = require("buildings");
...
collection.insertOne({ foo: buildings }, callback);
如果第一"targetEnvironment"
數組是空的,什麼都沒有插入,回調不是C alled,並沒有錯誤。但如果它被填充,一切都很好,回調被稱爲和文檔被正確插入... 我必須承認,我不知道如果問題是與Node或MongoDb驅動程序有關...
有人能幫助我嗎 ?
在升級之前,是否也做了同樣的插入工作? – metame
是的,我使用了Nodejs v0.12和MongoDb Driver v1.4。 – Paradox
你可以記錄錯誤或打開你的'mongod'的調試日誌嗎? – metame