整个文档
{
"_id": "5952e97a833244f2f94f1243",
"name": "Starcups",
"reviews": [
{
"author": "Simon Holmes",
"id": "5952ea74833244f2f94f1244",
"rating": 5,
"timestamp": "2013-07-15T21:00:00.000Z",
"reviewText": "What a great place.",
"createdOn": "2017-07-02T00:32:40.449Z"
},
{
"author": "Charlie Chaplin",
"id": "5952eb61833244f2f94f1245",
"rating": 3,
"timestamp": "2013-07-15T21:00:00.000Z",
"reviewText": "It was okay.",
"createdOn": "2017-07-02T00:32:40.449Z"
}
]
}
我有一个问题是在MongoDB中获取子文档的id。当我试图显示子文档的任何其他对象时,它工作正常。
例如
reviews[0].author
会告诉我" Simon Holmes"值。
但是
reviews[0].id
会显示空
怎么办?如果不在子文档中按id搜索,我就无法返回需要的对象。