所以我想在我的计算机上将我数据库的数据添加到mlab数据库中。我复制了数据(我假设是JSON)并尝试将其粘贴到我的mlab数据库中的集合中。
现在,问题是我的数据库中的ObjectIds导致错误,因为它不是有效的JSON。有谁知道如何解决这个问题?
示例文档
path
Mlab错误
JSON验证错误关闭我们在解析您的时遇到错误 JSON。请检查您的语法(例如,确保您使用的是双倍 引用您的字段名称和值),然后重试。
我测试了JSON lint中的代码,它给了我这个错误:
{
"_id" : ObjectId("5a8ae78844a5ba0d448a4cf7"),
"ratings" : [],
"reviews" : [],
"title" : "The Shape of Water",
"director" : "Guillermo Del Toro",
"length" : 123,
"genre" : "Drama",
"description" : "At a top secret research facility in the 1960s, a lonely janitor forms a unique relationship with an amphibious creature that is being held in captivity.",
"actors" : "French chick, Fish Dude",
"year" : 2018,
"pictureUrl" : "https://media.pathe.nl/nocropthumb/620x955/gfx_content/other/api/filmdepot/v1/movie/download/23452_94164_ps_sd-high.jpg",
"__v" : 18,
"averageRating" : 4
}
答案 0 :(得分:1)
mLab上的数据编辑器使用严格的MongoDB Extended JSON。有关详细信息,请参阅此处:docs.mongodb.com/manual/reference/mongodb-extended-json
在严格的MongoDB中,扩展JSON ObjectId("<id>")
需要{ "$oid": "<id>" }
。试试这个:
{
"_id" : {
"$oid": "5a8ae78844a5ba0d448a4cf7"
},
"ratings" : [],
"reviews" : [],
"title" : "The Shape of Water",
"director" : "Guillermo Del Toro",
"length" : 123,
"genre" : "Drama",
"description" : "At a top secret research facility in the 1960s, a lonely janitor forms a unique relationship with an amphibious creature that is being held in captivity.",
"actors" : "French chick, Fish Dude",
"year" : 2018,
"pictureUrl" : "https://media.pathe.nl/nocropthumb/620x955/gfx_content/other/api/filmdepot/v1/movie/download/23452_94164_ps_sd-high.jpg",
"__v" : 18,
"averageRating" : 4
}