我有mongo的文档:
{
"_id" : ObjectId("54eb5189ad9685bbb622ca52"),
"header" : {
"title" : "Project Name 1",
"header_img" : "project_name_1.png",
"project_stats" : {
"sqFt" : 20000,
"tons" : 300,
"duration" : "6 months",
"type" : "education facility",
"summary" : "Give quick summary of problem solved."
}
},
"row_project_detail" : {
"project_logo" : "project_name_1_logo.png",
"header" : "Project Name 1 was a project where...",
"paragraph" : "blah blah blah blah"
},
"row_1" : {
"img" : "project_name_2.png"
},
"row_2" : {
"img_1" : "project_name_3.png",
"img_2" : "project_name_4.png"
},
"row_3" : {
"img" : "project_name_5.png"
},
"row_4" : {
"img" : "project_name_6.png"
}
}
我尝试按db.projects.find({ header: { title: "Project Name 1"} });
进行查询,但不会产生结果。如何通过title
对象中的header
键进行查询?这是可能的还是我只需要复制title
子对象中的header
密钥并将其放在doc的根目录下?
答案 0 :(得分:1)
使用点符号:
db.projects.find({ "header.title": "Project Name 1"});