从MongoDB检索字段子集
要重试字段的子集,请在中使用点符号find()。让我们创建一个包含文档的集合-
> db.demo307.insertOne({
... "CleintId":101,
... "ClientDetails":{"ClientFirstName":"Chris","Age":34},
... "ClientCountryName":"US"
...}
...);
{
"acknowledged" : true,
"insertedId" : ObjectId("5e4eab88f8647eb59e56203c")
}
> db.demo307.insertOne({
... "CleintId":102,
... "ClientDetails":{"ClientFirstName":"David","Age":31},
... "ClientCountryName":"UK"
...}
...);
{
"acknowledged" : true,
"insertedId" : ObjectId("5e4eab97f8647eb59e56203d")
}在find()方法的帮助下显示集合中的所有文档-
> db.demo307.find();
这将产生以下输出-
{ "_id" : ObjectId("5e4eab88f8647eb59e56203c"), "CleintId" : 101, "ClientDetails" : { "ClientFirstName" : "Chris", "Age" : 34 }, "ClientCountryName" : "US" }
{ "_id" : ObjectId("5e4eab97f8647eb59e56203d"), "CleintId" : 102, "ClientDetails" : { "ClientFirstName" : "David", "Age" : 31 }, "ClientCountryName" : "UK" }以下是从MongoDB中检索字段子集的查询-
> db.demo307.find( {"ClientDetails.ClientFirstName":'David'}, {"ClientDetails.Age" : 0,"ClientCountryName":0,CleintId:0,_id:0});这将产生以下输出-
{ "ClientDetails" : { "ClientFirstName" : "David" } }热门推荐
10 新人红包祝福语简短精辟
11 幼师给毕业祝福语简短
12 生日高考祝福语妹妹简短
13 下飞机祝福语简短英文
14 元宵发客户祝福语简短
15 爸妈金婚文案祝福语简短
16 新郎朋友红包祝福语简短
17 虎年五一祝福语大全简短
18 出阁宴祝福语姐姐简短