Mongodb - >开发产品系列。对于图像,我有以下json:
"images":{
"id":"price-1234567890",
"caption":"image",
"file":{
"id":"price-1234567890-1",
"date_uploaded":"2014-10-01T00:00:00Z",
"length":"123",
"md5":"hasg",
"filename":"price-1234567890-1",
"url":"/images/folder/mongodb/a.png"
},
},
尝试插入该信息mongodb会显示以下信息错误:
无法解析json:字段中的第一个字符必须是[A-Za-z $ _],at (11,9)
并在上一个}中显示红色的错误,
可以嵌套另一组值吗? (在这种情况下文件内部图像)。
任何帮助表示感谢。
答案 0 :(得分:3)
我认为你想要的是创建一个对象数组。这将允许您在文件下有多个对象。
{
"images": {
"id": "price-1234567890",
"caption": "image",
"file": [{
"id": "price-1234567890-1",
"date_uploaded": "2014-10-01T00:00:00Z",
"length": "123",
"md5": "hasg",
"filename": "price-1234567890-1",
"url": "/images/folder/mongodb/a.png"
}, {
"id": "price-1234567890-1",
"date_uploaded": "2014-10-01T00:00:00Z",
"length": "123",
"md5": "hasg",
"filename": "price-1234567890-1",
"url": "/images/folder/mongodb/a.png"
}]
}
}
答案 1 :(得分:0)
在关闭“文件”对象的括号后删除逗号即可解决问题。
"images": {
"id":"price-1234567890",
"caption":"image",
"file": {
"id":"price-1234567890-1",
"date_uploaded":"2014-10-01T00:00:00Z",
"length":"123",
"md5":"hasg",
"filename":"price-1234567890-1",
"url":"/images/folder/mongodb/a.png"
}
},