如何在MongoDB中访问子数据并显示特定文档?
>db.demo450.insertOne({"Information":{"StudentDetails":{"StudentName":"Chris","StudentAge":21}}}); {
"acknowledged" : true,
"insertedId" : ObjectId("5e7b590e71f552a0ebb0a6e6")
}
>db.demo450.insertOne({"Information":{"StudentDetails":{"StudentName":"David","StudentAge":23}}});{
"acknowledged" : true,
"insertedId" : ObjectId("5e7b591a71f552a0ebb0a6e7")
}
>db.demo450.insertOne({"Information":{"StudentDetails":{"StudentName":"Mike","StudentAge":22}}});{
"acknowledged" : true,
"insertedId" : ObjectId("5e7b592271f552a0ebb0a6e8")
}在find()方法的帮助下显示集合中的所有文档-
> db.demo450.find();
这将产生以下输出-
{ "_id" : ObjectId("5e7b590e71f552a0ebb0a6e6"), "Information" : { "StudentDetails" : {
"StudentName" : "Chris", "StudentAge" : 21 } } }
{ "_id" : ObjectId("5e7b591a71f552a0ebb0a6e7"), "Information" : { "StudentDetails" : {
"StudentName" : "David", "StudentAge" : 23 } } }
{ "_id" : ObjectId("5e7b592271f552a0ebb0a6e8"), "Information" : { "StudentDetails" : {
"StudentName" : "Mike", "StudentAge" : 22 } } }以下是在MongoDB中查询子数据的查询-
> db.demo450.find({"Information.StudentDetails.StudentName":"David"});这将产生以下输出-
{ "_id" : ObjectId("5e7b591a71f552a0ebb0a6e7"), "Information" : { "StudentDetails" : {
"StudentName" : "David", "StudentAge" : 23 } } }热门推荐
2 孙媳妇祝福语简短
10 老板生日祝福语简短语
11 生日祝福语简短而有深意
12 牙医生日祝福语简短
13 海鲜送礼祝福语简短大全
14 儿子31岁祝福语简短
15 简短正能量生日祝福语
16 结婚祝福语亲姐姐简短
17 结婚婚庆祝福语简短
18 兔年祝福语简短100字