在MongoDB 隐藏ID字段
> db.demo575.insertOne({id:101,Information:{Name:"Chris",Age:21}});{
"acknowledged" : true, "insertedId" : ObjectId("5e916a55581e9acd78b427f7")
}
> db.demo575.insertOne({id:102,Information:{Name:"David",Age:20}});{
"acknowledged" : true, "insertedId" : ObjectId("5e916a5f581e9acd78b427f8")
}
> db.demo575.insertOne({id:101,Information:{Name:"Bob",Age:23}});{
"acknowledged" : true, "insertedId" : ObjectId("5e916a67581e9acd78b427f9")
}在find()方法的帮助下显示集合中的所有文档-
> db.demo575.find();
这将产生以下输出-
{ "_id" : ObjectId("5e916a55581e9acd78b427f7"), "id" : 101, "Information" : { "Name" : "Chris", "Age" : 21 } }
{ "_id" : ObjectId("5e916a5f581e9acd78b427f8"), "id" : 102, "Information" : { "Name" : "David", "Age" : 20 } }
{ "_id" : ObjectId("5e916a67581e9acd78b427f9"), "id" : 101, "Information" : { "Name" : "Bob", "Age" : 23 } }以下是隐藏id字段值并显示rest的查询-
> db.demo575.find({id:101},{"Information.Name":1});这将产生以下输出-
{ "_id" : ObjectId("5e916a55581e9acd78b427f7"), "Information" : { "Name" : "Chris" } }
{ "_id" : ObjectId("5e916a67581e9acd78b427f9"), "Information" : { "Name" : "Bob" } }热门推荐
10 祝女儿简短祝福语大全
11 大学新年祝福语简短创意
12 元旦适合的祝福语简短
13 朋友出远门祝福语简短
14 初六简短的祝福语
15 祝男孩生日祝福语简短
16 同事调离的祝福语简短
17 拜年红包的祝福语简短
18 妈妈生日祝福语简短励志