我试图在以下JSON文档上执行我的第一个mongoDB查询,我使用mongoimport将其添加到数据库中。
{
"questions": [
{
"questionEntry": {
"id": 1,
"info": {
"seasonNumber": 1,
"episodeNumber": 1,
"episodeName": "Days Gone Bye"
},
"questionItem": {
"theQuestion": "q1",
"attachedElement": {
"type": 1,
"value": ""
}
},
"options": [
{
"type": 1,
"value": "o1"
},
{
"type": 1,
"value": "o1"
}
],
"answer": {
"questionId": 1,
"answer": 1
},
"metaTags": [
"Season 1",
"Episode 1",
"Rick Grimmes"
]
}
},
{
"questionEntry": {
"id": 1,
"info": {
"seasonNumber": 1,
"episodeNumber": 1,
"episodeName": "Days Gone Bye"
},
"questionItem": {
"theQuestion": "q2",
"attachedElement": {
"type": 1,
"value": ""
}
},
"options": [
{
"type": 1,
"value": "o2"
},
{
"type": 1,
"value": "o2"
}
],
"answer": {
"questionId": 1,
"answer": 1
},
"metaTags": [
"Season 1",
"Episode 1",
"Rick Grimmes",
"Glenn Rhee"
]
}
}
]
}
我试过db.questions.find({"questions.questionEntry.id" : "1"})
& db.questions.find({"questions.questionEntry.id" : "1"})
加上其他几个版本来尝试查询questionEntry的id字段。每次命令提示符只返回到一个新的命令提示行"没有"!?
如果我运行db.questions.find()
,则返回上面显示的集合。
我在这里做错了什么?
答案 0 :(得分:1)
您的id
是一个数字,而不是字符串。
所以以下内容应该有效:
db.questions.find({"questions.questionEntry.id" : 1})