Get the App
SLTechnology News&Howtos  ›  Database  › 

How to realize range Operation in MongoDB

Shulou Source: shulou.com Published: 2022-05-31 21:13:51 10月02日 Update

MongoDB中怎么实现范围运算,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。

"$in":在范围之中

"$nin":不再范围之中

范例:查询姓名为"赵一"、"王八"的信息

> db.emp.find({"name":{"$in":["赵一","王八"]}}).pretty();

{

"_id" : ObjectId("599108423268c8e84253be26"),

"name" : "赵一",

"sex" : "男",

"age" : 30,

"sal" : 1000,

"loc" : "北京"

}

{

"_id" : ObjectId("599108433268c8e84253be2d"),

"name" : "王八",

"sex" : "男",

"age" : 35,

"sal" : 8000,

"loc" : "北京"

}

范例:查询姓名不是"赵一"、"王八"的信息

> db.emp.find({"name":{"$nin":["赵一","王八"]}}).pretty();

{

"_id" : ObjectId("599108423268c8e84253be27"),

"name" : "钱二",

"sex" : "女",

"age" : 22,

"sal" : 5000,

"loc" : "上海"

}

{

"_id" : ObjectId("599108423268c8e84253be28"),

"name" : "孙三",

"sex" : "男",

"age" : 40,

"sal" : 2000,

"loc" : "深圳"

}

{

"_id" : ObjectId("599108423268c8e84253be29"),

"name" : "李四",

"sex" : "女",

"age" : 30,

"sal" : 7000,

"loc" : "北京"

}

{

"_id" : ObjectId("599108423268c8e84253be2a"),

"name" : "周五",

"sex" : "女",

"age" : 30,

"sal" : 6400,

"loc" : "北京"

}

{

"_id" : ObjectId("599108423268c8e84253be2b"),

"name" : "吴六",

"sex" : "男",

"age" : 30,

"sal" : 2500,

"loc" : "重庆"

}

{

"_id" : ObjectId("599108423268c8e84253be2c"),

"name" : "郑七",

"sex" : "女",

"age" : 50,

"sal" : 4700,

"loc" : "成都"

}

看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注行业资讯频道,感谢您对的支持。

Tags: Son of a bitch Beijing scope medium information examples help query calculation clarity content name this article novice more knowledge industry information information channel Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Linux NVidia OPPO Reno Xiaomi