从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 好听的元旦简短祝福语