使用文档评估MongoDB集合中的其他值之一
要评估一个或多个值,请将$or与一起使用find()。让我们创建一个包含文档的集合-
> db.demo174.insertOne({"StudentName":"Chris","CountryName":"US"});
{
"acknowledged" : true,
"insertedId" : ObjectId("5e383c709e4f06af551997e5")
}
> db.demo174.insertOne({"StudentName":"David","CountryName":"UK"});
{
"acknowledged" : true,
"insertedId" : ObjectId("5e383c779e4f06af551997e6")
}
> db.demo174.insertOne({"StudentName":"Bob","CountryName":"AUS"});
{
"acknowledged" : true,
"insertedId" : ObjectId("5e383c7e9e4f06af551997e7")
}在find()方法的帮助下显示集合中的所有文档-
> db.demo174.find();
这将产生以下输出-
{ "_id" : ObjectId("5e383c709e4f06af551997e5"), "StudentName" : "Chris", "CountryName" : "US" }
{ "_id" : ObjectId("5e383c779e4f06af551997e6"), "StudentName" : "David", "CountryName" : "UK" }
{ "_id" : ObjectId("5e383c7e9e4f06af551997e7"), "StudentName" : "Bob", "CountryName" : "AUS" }以下是评估一个或多个值的查询。在这里,我们获取了多个值,即学生“David”或国家“US”-
> db.demo174.find({$or:[{"StudentName":"David"},{"CountryName":"US"}]});这将产生以下输出-
{ "_id" : ObjectId("5e383c709e4f06af551997e5"), "StudentName" : "Chris", "CountryName" : "US" }
{ "_id" : ObjectId("5e383c779e4f06af551997e6"), "StudentName" : "David", "CountryName" : "UK" }热门推荐
10 新人红包祝福语简短精辟
11 幼师给毕业祝福语简短
12 生日高考祝福语妹妹简短
13 下飞机祝福语简短英文
14 元宵发客户祝福语简短
15 爸妈金婚文案祝福语简短
16 新郎朋友红包祝福语简短
17 虎年五一祝福语大全简短
18 出阁宴祝福语姐姐简短