当前位置:网站首页>MongoDB相关记录
MongoDB相关记录
2022-08-02 03:34:00 【deft_】
curd:
- db.xxx.find、findOne
- db.xxx.insert() insertOne insertMany
- db.xxx.update() (删除添加表示字段)
- db.xxx.upsert()
查询操作符
数值条件
(>) 大于 - $gt
(<) 小于 - $lt
(>=) 大于等于 - $gte
(<= ) 小于等于 - $lte
其他条件
$all
例:{ field: { $all: [ value , value1 … ] } || value}
匹配field字段中包含all数组或value值的数据
$in
例:{ field: { $in: [ value , value1 … ] } || value}
匹配field字段中键值为value或value1的数据
$nin
例:{ field: { $nin: [ value , value1 … ] } || value}
匹配field字段中键值不为value或value1的数据
$ne
{field: {$ne: value}}
匹配field字段中键值不等于value的数据
逻辑操作符
$and
例{ $and: [ { name: “Nick” }, { price: { $lt:100 } } ] }
and指定一个至少包含两个表达式的数组,选择出满足该数组中所有表达式的文档
$or
例{ $or: [ { name: “Nick” }, { price: { $lt:100 } } ] }
选择name为“Nick” 或 price值小于100的文档数据
$nor
例{ $nor: [ { name: “Nick” }, { price: { $lt:100 } } ] }
选择name不为“Nick”,price值不小于100的文档数据
$not
例{ price : { $not: { $lt : 50 } } }
选择price值不小于50的文档数据是
元素查询
$exists
例{ test : { KaTeX parse error: Expected 'EOF', got '}' at position 22: …: true / false }̲ } 如果exists的值为true,选择存在该(test)字段的文档;若值为false则选择不包含该字段的文档
$mod
例{ price : { $mod: [2,0] } }
选择集合中 price 字段的值为 2 的 0 次模数的所有文档,例如 price 值等于 4、6、8、… 的文档
数据类型查询
$type
例{ name : { $type: < number > } }
选择集合中 name 字段的值为 类型的所有文档,此时想查出数据,则应为 2 (字符串)
$where
$ where操作符非常灵活,可以任意与js相结合进行查询(但返回较慢,一般情况下避免使用$where)
例:
变量形式
db.user.find( { $where: “this.name == this.user” } )
db.user.find( { $where: “obj.name == obj.user” } )
函数方法形式
db.fruit.find( { $where: function() { return (this.name == this.user) } } )
db.fruit.find( { $where: function() { return obj.name == obj.user } } )
边栏推荐
猜你喜欢
随机推荐
【 LeetCode 】 design list
逆序对数量与归并排序
Laptop charging problems
Introduction and mock implementation of list:list
Beckhoff ET2000 listener use
Mongoose无法更新时间戳
STM32 CAN 介绍以及相关配置
单 词替换
【Connect the heart rate sensor to Arduino to read the heart rate data】
openssl-1.1.1g 交叉编译注意事项
v-model修饰符
HAL库笔记——通过按键来控制LED(基于正点原子STM32F103ZET6精英板)
change file extension
bluez5.50+pulseaudio实现蓝牙音响音频播放
[Database] Four characteristics of transaction
设置图片纵横比
进程(中):进程状态、进程地址空间
剑指Offer 33.二叉搜索树的后序遍历序列
判断回文
Comparison between Boda Industrial Cloud and Alibaba Cloud