专注于 JetBrains IDEA 全家桶,永久激活,教程
持续更新 PyCharm,IDEA,WebStorm,PhpStorm,DataGrip,RubyMine,CLion,AppCode 永久激活教程

MongoDB数据库常用SQL命令 — MongoDB可视化工具Robo 3T

1、db.collection.updateMany() 修改集合中的多个文档。

db.getCollection(‘user’).find({”pId”:”3332a512df604a74a72f267cf246″}).updateMany({”pId”:”c8018dd802a644a19517790336f”})

2、模糊查询

db.getCollection(‘user’).find({name:{$regex:”AA”}})

db.getCollection(‘user’).find({”name”:{ $regex:/AA/ }})

db.getCollection(‘user’).find({name:/AA/})

3、查询name是否为AA,BB,CC,DD的记录

db.getCollection(‘user’).find({”name”:{$in:[”AA”,”BB”,”CC”,”DD”]}}) //属于 – in

db.getCollection(‘user’).find({”name”:{$nin:[”AA”,”BB”,”CC”,”DD”]}}) //不属于 – nin

4、按照时间排序

db.getCollection(‘user’).find({name:{$regex:”AA”}}).sort({ lastUpdatedTime : 1 }) //时间正序

db.getCollection(‘user’).find({name:{$regex:”AA”}}).sort({ lastUpdatedTime : -1 }) //时间倒序

5、字段是否存在

db.getCollection(‘user’).find({age:{$exists:true}})

6、对数组中的某一个元素进行查询

db.getCollection(‘template’).find({”content.pages.questions.type”:”A”})

7、limit() 和skip() 方法操作

使用limit() 方法来读取指定数量的数据,limit方法接受一个数字参数作为读取的记录条数

使用skip() 方法来跳过指定数量的数据,skip方法接受一个数字参数作为跳过的记录条数

db.getCollection(‘user’).find({}).limit(5).skip(1) — 跳过第1条,展示第2条到第6条

8、时间范围查询

greater than(大于)

less than(小于)

(>) 大于 – $gt

(<) 小于 – $lt

(>=) 大于等于 – $gte

(<= ) 小于等于 – $lte

db.getCollection(‘student’).find({”createdTime”:{$lt:new Date(2019,8,16)}}) //创建时间在2019.8.16之前的记录

db.getCollection(‘student’).find({”createdTime”:{$lte:new Date(2019,8,31),$gte:new Date(2019,3,1)}}) //创建时间在2019.3.1到2019.8.31之间的记录

9、更新语句,如果你要修改多条相同的文档,则需要设置 multi 参数为 true

db.getCollection(‘user’).update({”name”:”张三”},{$set:{”name”:”李四”}},{multi:true})

文章永久链接:https://tech.souyunku.com/48472

未经允许不得转载:搜云库技术团队 » MongoDB数据库常用SQL命令 — MongoDB可视化工具Robo 3T

JetBrains 全家桶,激活、破解、教程

提供 JetBrains 全家桶激活码、注册码、破解补丁下载及详细激活教程,支持 IntelliJ IDEA、PyCharm、WebStorm 等工具的永久激活。无论是破解教程,还是最新激活码,均可免费获得,帮助开发者解决常见激活问题,确保轻松破解并快速使用 JetBrains 软件。获取免费的破解补丁和激活码,快速解决激活难题,全面覆盖 2024/2025 版本!

联系我们联系我们