当前位置:网站首页>【MongoDB】MongoDB数据库的基础使用,特殊情况以及Mongoose的安装和创建流程(含有Mongoose固定版本安装)
【MongoDB】MongoDB数据库的基础使用,特殊情况以及Mongoose的安装和创建流程(含有Mongoose固定版本安装)
2022-07-28 21:24:00 【小王宝友】
MongoDB的比较运算符
- KaTeX parse error: Expected '}', got 'EOF' at end of input: …tion.find({元素:{ lt:数值}})
- KaTeX parse error: Expected '}', got 'EOF' at end of input: …tion.find({元素:{ gt :数值}})
- KaTeX parse error: Expected '}', got 'EOF' at end of input: …tion.find({元素:{ gte:数值}})
- KaTeX parse error: Expected '}', got 'EOF' at end of input: …tion.find({元素:{ lte:数值}})
- KaTeX parse error: Expected '}', got 'EOF' at end of input: …tion.find({元素:{ ne:数值}})
- 区间判断(可以传入多个条件)
- db.collection.find({元素:{ g t : 数值 1 , gt:数值1, gt:数值1,lt:数值2}})
- 表示大于数值1并且小于数组2
- 多条件区间判断
- db.collection.find({$or:[{元素:数据1},{元素:数据2},…]})
- 表示判断元素满足数据1的情况或是满足数据2的情况
MongoDB查看固定数据
在使用时,-绝对不能执行不带条件-的查询
查看集合前10条数据
- db.collection.find().limit(10);
查看11-20条数据
- skip()用于跳过固定条数的数据
- db.collection.find().skip(10).limit(10);
分页固定公式
- skip((页码-1)*每页固定的条数).limit(每页固定的条数);
注意:
- MongoDB会自动的调整skip和limit的顺序
MongoDB查找特殊情况
- 在直接使用find()方法进行查找时返回的是一个数组,无法获取到需要查找的值,即可使用[0]或是findOne()方法进行查找
- 当两个集合中相同意思的编码不一致时(在数据属性较多的情况下不好查找,所以尽量的在创建集合时让编码一致),创建一个变量将值进行接收,在另一个集合中进行查找时使用该变量
- 在查询时如果数据没有正确的出现,检查查询条件的数据类型,可能是数据类型不一致导致的结果异常
- 当查询时只想查找个别数据时,可以在第二个参数的位置来设置查询结果的投影(使用投影时1表示显示,0表示不显示,_id默认显示)
- db.collection.find({},{元素1:1,元素2:0,…})
MongoDB对数值进行修改(增加或是减少)
- $inc增加(减少)数值(increment)
- db.collection.updateMany({条件},{$inc:{修改内容}})
MongoDB对于数据进行排序操作
- MongoDB默认的是使用_id进行排序
- 可以使用sort()方法需要传递一个对象来指定文档的排序规则(1为升序排列,-1表示降序排列),也可以传递多个对象
- db.collection.find().sort(元素1:1,元素2:-1,…);
- 先使用元素1进行升序排序,当元素1相同时,在对元素2进行降序排序
Mongoose
- 使用步骤:
- 在终端中输入命令 npm i [email protected](版本号)
- 链接数据库
- 创建约束Schema
- 创建模块Model
注意
- limit() skip() sort()可以以任意顺序进行编写
边栏推荐
- Paper reading vision gnn: an image is worth graph of nodes
- LeetCode练习3——回文数
- Configuration and official document of Freia library [tips]
- HP ProLiant DL380 boot from USB flash drive, press which key
- This year, MediaTek 5g chip shipments are expected to reach 50million sets!
- Leetcode101. Symmetric binary tree
- shell脚本基础——Shell运行原理+变量、数组定义
- Submission records of frontiers Publishing House (with status changes)
- No code development platform management background tutorial
- 软件测试面试笔试题及答案(软件测试题库)
猜你喜欢

Yolov5 improvement 15: network lightweight method deep separable convolution

Nacos配置热更新的4种方式、读取项目配置文件的多种方式,@value,@RefreshScope,@NacosConfigurationProperties

Target detection notes - overview and common data sets
![Padim [anomaly detection: embedded based]](/img/11/834d8b4fdd39959a9dd380e179d317.png)
Padim [anomaly detection: embedded based]
![Mspba [anomaly detection: representation_based]](/img/95/1f7390ec024a2865acb9e9a41100b1.png)
Mspba [anomaly detection: representation_based]

PCA学习

高等数学解题常用公式笔记总结

Paper reading vision gnn: an image is worth graph of nodes

定了!哪吒S全系产品将于7月31日上市发售

18 diagrams, intuitive understanding of neural networks, manifolds and topologies
随机推荐
cannot resize variables that require grad
【图像分割】基于方向谷形检测实现静脉纹路分割附MATLAB代码
OSV_ q Expected all tensors to be on the same device, but found at least two devices, cuda:0
OSV-q ValueError: axes don‘t match array
希捷发布全新RISC-V架构处理器:机械硬盘相关性能暴涨3倍
DirectX repair tool download (where is exagear simulator package)
Servlet的使用手把手教学(一)
MySQL常用的日期时间函数
Es learning directory
投资1450亿欧元!欧盟17国宣布联合发展半导体技术
shell脚本基础——Shell运行原理+变量、数组定义
【C语言】三子棋小游戏实现
WebApplicationType#deduceFromClasspath
This year, MediaTek 5g chip shipments are expected to reach 50million sets!
B站713故障后的多活容灾建设|TakinTalks大咖分享
Migration from IPv4 to IPv6
In 2020, the top ten domestic IC design enterprises will be exposed! These five industrial challenges still need to be overcome!
Leetcode 199. right view of binary tree
It's settled! All products of Nezha s will be launched on July 31
UNET [basic network]