在哈希MongoDB中查找?
要在哈希MongoDB中查找,可以使用dot(。)表示法。首先让我们创建一个包含文档的集合
> db.hashDemo.insertOne({"ClientName":"Larry","ClientAge":23,"ClientDetails":{"isEducated": true, "ClientProject" : "University Management"}});
{
"acknowledged" : true,
"insertedId" : ObjectId("5ca1ef1266324ffac2a7dc5e")
}
> db.hashDemo.insertOne({"ClientName":"Chris","ClientAge":26,"ClientDetails":{
"isEducated":false, "ClientProject" : "Online Book Store"}});
{
"acknowledged" : true,
"insertedId" : ObjectId("5ca1ef7766324ffac2a7dc5f")
}
以下是在find()
方法的帮助下显示集合中所有文档的查询
> db.hashDemo.find().pretty();
这将产生以下输出
{"_id" : ObjectId("5ca1ef1266324ffac2a7dc5e"),
"ClientName" : "Larry",
"ClientAge" : 23,
"ClientDetails" : {
"isEducated" : true,
"ClientProject" : "University Management"
}
}
{
"_id" : ObjectId("5ca1ef7766324ffac2a7dc5f"),
"ClientName" : "Chris",
"ClientAge" : 26,
"ClientDetails" : {
"isEducated" : false,
"ClientProject" : "Online Book Store"
}
}
以下是在哈希MongoDB中查找的查询
> db.hashDemo.find({"ClientDetails.isEducated" : false, "ClientDetails.ClientProject" : "OnlineBook Store"}).pretty();
这将产生以下输出
{"_id" : ObjectId("5ca1ef7766324ffac2a7dc5f"),
"ClientName" : "Chris",
"ClientAge" : 26,
"ClientDetails" : {
"isEducated" : false,
"ClientProject" : "Online Book Store"
}
}
以上是 在哈希MongoDB中查找? 的全部内容, 来源链接: utcz.com/z/355620.html