当前位置:网站首页>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 } } )
边栏推荐
猜你喜欢
随机推荐
idea中创建jsp项目详细步骤
【TCS3200 color sensor and Arduino realize color recognition】
视频监控平台-国标28181-2016版平台,已公网部署
剑指Offer 64.求1+2+...+n 递归+&&
学习(三):事件的订阅与发布
只出现一次的字符
音视频文件码率与大小计算
基础IO(下):软硬链接和动静态库
Based on the raspberry pie smart luggage development environment set up
unity相关的功能链接
v-model修饰符
学习(四):显示FPS,和自定义显示调试
机械臂运动学解析
【MQ-3 Alcohol Detector and Arduino Detect Alcohol】
2020 - AAAI - 图像修复 Image Inpainting论文导读 -《Region Normalization for Image Inpainting》
【plang 1.4.4】编写茶几玛丽脚本
龙芯2K1000使用nfs挂载文件系统进行使用
单 词替换
【plang1.4.3】编写水母动画脚本
如何搭建私有云盘?