如何使用$ lte,$ in和$ not查询MongoDB的值以获取特定值?
首先让我们创建一个包含文档的集合-
> db.demo130.insertOne(
... {
...
... "PlayerDetails":[{Score:56},{Score:78},{Score:89},{Score:97}]
... }
... );
{
"acknowledged" : true,
"insertedId" : ObjectId("5e3065bf68e7f832db1a7f6d")
}
> db.demo130.insertOne(
... {
...
... "PlayerDetails":[{Score:45},{Score:56}]
... }
... );
{
"acknowledged" : true,
"insertedId" : ObjectId("5e3065c068e7f832db1a7f6e")
}在find()方法的帮助下显示集合中的所有文档-
> db.demo130.find();
这将产生以下输出-
{ "_id" : ObjectId("5e3065bf68e7f832db1a7f6d"), "PlayerDetails" : [ { "Score" : 56 }, { "Score" : 78 }, { "Score" : 89 }, { "Score" : 97 } ] }
{ "_id" : ObjectId("5e3065c068e7f832db1a7f6e"), "PlayerDetails" : [ { "Score" : 45 }, { "Score" : 56 } ] }以下是要获取的查询-
> db.demo130.find({
... "PlayerDetails.Score": {
... "$eq": 56,
... "$not": { "$gt": 56}
... }
... })这将产生以下输出-
{ "_id" : ObjectId("5e3065c068e7f832db1a7f6e"), "PlayerDetails" : [ { "Score" : 45 }, { "Score" : 56 } ] }热门推荐
10 新人红包祝福语简短精辟
11 幼师给毕业祝福语简短
12 生日高考祝福语妹妹简短
13 下飞机祝福语简短英文
14 元宵发客户祝福语简短
15 爸妈金婚文案祝福语简短
16 新郎朋友红包祝福语简短
17 虎年五一祝福语大全简短
18 出阁宴祝福语姐姐简短