使用文档评估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 送给学长毕业祝福语简短