GeekIt

MongoDB命令速查

mongosh 连接、集合管理、CRUD、聚合、索引、权限、副本集分片与备份恢复等 172 条命令

共 172 条命令 · 10 类场景 · 点击右侧图标可复制

命令 / 语句说明复制
mongosh "mongodb://app:密码@10.0.0.5:27017/app_db?authSource=admin"通过 URI 连接,authSource 指定账号所在库(账号建在 admin 时必填)
mongosh --host 10.0.0.5 --port 27017 -u app -p --authenticationDatabase admin分参数连接,密码以交互方式输入,避免留在命令历史
mongosh "mongodb+srv://app:密码@cluster0.abcd.mongodb.net/app_db"连接 Atlas 副本集,自动从 SRV 记录发现节点
mongosh "mongodb://10.0.0.5:27017,10.0.0.6:27017/app_db?replicaSet=rs0&readPreference=secondaryPreferred"直连副本集并按需从从库读取
mongosh --tls --tlsCAFile /etc/ssl/mongo-ca.pem --host 10.0.0.5:27017 -u app -pTLS 加密连接,自签 CA 必须显式指定
mongosh --quiet --eval "db.runCommand({ ping: 1 })"非交互执行单条命令,脚本与巡检常用
mongosh "mongodb://app:密码@10.0.0.5:27017/app_db" --file /data/scripts/init.js执行 JS 脚本文件,适合批量初始化
mongosh --norc --nodb跳过 .mongoshrc.js 且不连接实例,用于纯 JS 计算
mongosh --eval "db.getMongo().getDBNames()"列出所有数据库名,等价于 adminCommand listDatabases
db.runCommand({ connectionStatus: 1 })查看当前认证用户与可用角色,排查权限问题第一步
show dbs; show collections; show users常用 show 命令:库、集合、用户一目了然
db.help(); db.users.help()查看库与集合支持的方法列表
db.getMongo().setReadPref("secondaryPreferred")当前会话切换读偏好,报表类查询减轻主节点压力
db.getSiblingDB("admin").shutdownServer()优雅关闭实例(副本集成员会先尝试让出主节点)
命令 / 语句说明复制
use app_db切换数据库,不存在时会在首次写入后创建
db.dropDatabase()删除当前库(不可恢复,执行前务必确认库名)
db.createCollection("events", { capped: true, size: 10485760, max: 100000 })创建固定集合,适合日志缓冲与环形队列
db.createCollection("metrics", { timeseries: { timeField: "ts", metaField: "meta", granularity: "minutes" } })5.0+ 时序集合,监控指标压缩率更高
db.createCollection("users", { validator: { $jsonSchema: { bsonType: "object", required: ["name"], properties: { name: { bsonType: "string" } } } }, validationLevel: "moderate", validationAction: "warn" })写入前的 JSON Schema 校验,先 warn 观察再改 error
db.getCollectionNames().sort()列出当前库所有集合
db.getCollectionInfos({ name: "users" })查看集合选项、校验规则与类型(普通/时序/视图)
db.users.renameCollection("users_bak")重命名集合,同库内为元数据操作,秒级完成
db.users.drop()删除集合及其全部索引,不可回滚
db.createView("vip_users", "users", [{ $match: { vip: true } }, { $project: { name: 1, city: 1 } }])创建只读视图,封装常用过滤逻辑
db.users.stats(1024 * 1024)集合统计:文档数、存储大小、索引大小(单位 MB)
db.stats(1024 * 1024)整库统计:数据量、存储量、索引量与集合数
db.users.storageSize(); db.users.dataSize()对比磁盘占用与逻辑数据量,判断压缩率与碎片
db.adminCommand({ listDatabases: 1, nameOnly: true })仅列库名,权限受限账号也可用
db.users.validate({ full: true })校验集合与索引完整性,异常时先备份再修复
db.users.isCapped()判断集合是否为固定集合
命令 / 语句说明复制
db.users.insertOne({ name: "tom", age: 28, tags: ["vip"], createdAt: new Date() })插入单个文档,自动生成 ObjectId
db.users.insertMany([{ name: "tom" }, { name: "jerry" }], { ordered: false })批量插入,ordered:false 允许部分失败继续写
db.users.insertOne({ name: "tom" }, { writeConcern: { w: "majority", j: true } })指定写关注,多数派落盘后返回,避免切换丢数据
db.users.bulkWrite([{ insertOne: { document: { name: "a" } } }, { updateOne: { filter: { name: "b" }, update: { $set: { age: 20 } } } }])混合写入,减少网络往返
db.users.find({ age: { $gte: 18 } }).limit(10)条件查询并限制返回条数
db.users.findOne({ name: "tom" })返回单个文档,等价于 find().limit(1) 的结果
db.users.find({}, { name: 1, age: 1, _id: 0 })投影:只返回指定字段,减少网络传输
db.users.find().sort({ createdAt: -1 }).skip(20).limit(10)分页查询,深分页建议改用游标条件(createdAt < 上一页末值)
db.users.updateOne({ name: "tom" }, { $set: { age: 29 } })更新首个匹配文档的指定字段
db.users.updateMany({ status: "inactive" }, { $set: { archived: true } })批量更新,注意影响行数与锁范围
db.users.updateOne({ _id: ObjectId("6540c1f2a1b2c3d4e5f60718") }, { $inc: { loginCount: 1 }, $currentDate: { lastLogin: true } })自增计数并写入服务器当前时间
db.users.updateOne({ _id: ObjectId("6540c1f2a1b2c3d4e5f60718") }, { $addToSet: { tags: "vip" } })数组去重追加,等价于集合语义
db.users.updateOne({ _id: ObjectId("6540c1f2a1b2c3d4e5f60718") }, { $pull: { tags: "vip" } })删除数组中匹配的元素
db.users.replaceOne({ _id: ObjectId("6540c1f2a1b2c3d4e5f60718") }, { name: "tom", age: 30 })整文档替换,未给出的字段会丢失
db.users.findOneAndUpdate({ name: "tom" }, { $set: { vip: true } }, { returnDocument: "after" })更新并返回结果,适合计数与抢占场景
db.users.deleteOne({ _id: ObjectId("6540c1f2a1b2c3d4e5f60718") })删除单个文档
db.users.deleteMany({ createdAt: { $lt: ISODate("2026-01-01T00:00:00Z") } })按时间批量清理历史数据,大批量建议分批执行
db.users.countDocuments({ status: "active" })精确计数,条件复杂时比 estimatedDocumentCount 慢
db.users.estimatedDocumentCount()读取元数据快速估算总数,无过滤条件时使用
db.users.distinct("city")返回字段去重值列表,可带查询条件
命令 / 语句说明复制
db.users.find({ age: { $gt: 20, $lte: 30 } })范围查询,多个操作符可组合在同一字段
db.users.find({ status: { $in: ["active", "trial"] } })$in 命中集合内任意值,配合索引效果好
db.users.find({ phone: { $exists: true }, email: { $ne: null } })判断字段存在与不为空
db.users.find({ name: /^tom/i })前缀正则可用索引,非前缀正则会全集合扫描
db.users.find({ "address.city": "上海" })查询嵌套文档字段,路径需用引号包裹
db.users.find({ tags: "vip" })数组包含查询,命中数组任一元素
db.users.find({ items: { $elemMatch: { sku: "A1", qty: { $gt: 2 } } } })同一数组元素内多条件同时成立,避免跨元素误匹配
db.users.find({ $or: [{ vip: true }, { score: { $gte: 90 } }] })或条件查询,$or 各分支最好都有索引
db.users.aggregate([{ $match: { status: "active" } }, { $group: { _id: "$city", total: { $sum: 1 } } }, { $sort: { total: -1 } }, { $limit: 10 }])分组统计 Top10,$match 放在管道最前可利用索引
db.orders.aggregate([{ $unwind: "$items" }, { $group: { _id: "$items.sku", qty: { $sum: "$items.qty" }, amount: { $sum: { $multiply: ["$items.price", "$items.qty"] } } } }])展开数组后按 SKU 汇总数量与金额
db.orders.aggregate([{ $lookup: { from: "users", localField: "userId", foreignField: "_id", as: "user" } }, { $unwind: "$user" }])左连接用户集合,等同于 SQL JOIN
db.orders.aggregate([{ $project: { _id: 0, orderNo: 1, total: { $sum: "$items.price" }, month: { $dateToString: { format: "%Y-%m", date: "$createdAt" } } } }])字段投影与计算字段,可在管道中做格式化
db.orders.aggregate([{ $sortByCount: "$status" }])按字段分组计数并降序,$group + $sort 的简化写法
db.orders.aggregate([{ $facet: { byStatus: [{ $sortByCount: "$status" }], total: [{ $count: "n" }] } }])一次扫描输出多个维度的统计结果
db.orders.aggregate([{ $match: { city: "上海" } }, { $group: { _id: "$status", n: { $sum: 1 } } }], { allowDiskUse: true })允许落盘,突破聚合 100MB 内存限制
db.orders.aggregate([{ $match: { orderNo: "NO20261102001" } }], { hint: { orderNo: 1 } })强制使用指定索引,排查优化器选错索引
db.orders.aggregate([{ $bucket: { groupBy: "$amount", boundaries: [0, 100, 500, 1000], default: "other", output: { n: { $sum: 1 } } } }])按区间分桶统计,做金额分布分析很方便
命令 / 语句说明复制
db.users.createIndex({ name: 1 }, { unique: true })创建唯一索引,重复数据会导致建索引失败
db.users.createIndex({ email: 1 }, { unique: true, sparse: true })稀疏唯一索引,允许大量文档缺少该字段
db.users.createIndex({ city: 1, age: -1 }, { name: "idx_city_age" })复合索引,字段顺序决定可用的查询前缀
db.users.createIndex({ tags: 1 })数组字段建多键索引,每个元素各占一条索引项
db.users.createIndex({ content: "text" }, { default_language: "none" })全文索引,中文需配合分词方案(如 Atlas Search)
db.users.createIndex({ location: "2dsphere" })地理位置索引,支持 $near 与 $geoWithin
db.users.createIndex({ createdAt: 1 }, { expireAfterSeconds: 2592000 })TTL 索引,30 天后自动删除文档(后台每 60 秒扫描)
db.users.createIndex({ email: 1 }, { partialFilterExpression: { status: "active" } })部分索引,只为满足条件的文档建索引,体积更小
db.users.createIndex({ orderNo: 1 }, { commitQuorum: "majority" })副本集建索引的确认策略,避免从库建索引被中断
db.users.getIndexes()查看集合全部索引定义与选项
db.users.dropIndex("idx_city_age")按名称删除索引,重建前先确认没有查询依赖
db.users.dropIndexes()删除除 _id 外的全部索引(谨慎,会影响线上查询)
db.users.hideIndex("idx_city_age")隐藏索引做灰度验证,确认无影响后再真正删除
db.users.aggregate([{ $indexStats: {} }])查看索引使用次数,长期为 0 的索引可评估清理
db.users.find({ name: "tom" }).explain("executionStats")重点看 stage(IXSCAN/COLLSCAN)、totalKeysExamined、totalDocsExamined
db.users.aggregate([{ $match: { name: "tom" } }], { explain: true })聚合管道执行计划,确认 $match 是否下推到索引
db.users.stats().indexSizes查看各索引占用空间,评估内存与磁盘成本
命令 / 语句说明复制
db.createUser({ user: "app", pwd: "密码", roles: [{ role: "readWrite", db: "app_db" }] })创建业务读写账号,最小权限原则
db.createUser({ user: "ro", pwd: "密码", roles: [{ role: "read", db: "app_db" }] })创建只读账号,供报表与临时排查使用
db.createUser({ user: "dba", pwd: "密码", roles: [{ role: "root", db: "admin" }] })创建管理员账号,仅限运维人员持有
db.changeUserPassword("app", "新密码")修改账号密码,修改后旧连接不受影响
db.updateUser("app", { roles: [{ role: "readWrite", db: "app_db" }, { role: "dbAdmin", db: "app_db" }] })整体覆盖角色列表,注意不要漏掉原有权限
db.grantRolesToUser("app", [{ role: "dbAdmin", db: "app_db" }])追加角色,比 updateUser 更安全
db.revokeRolesFromUser("app", [{ role: "dbAdmin", db: "app_db" }])回收指定角色
db.dropUser("app")删除账号,账号正在使用的连接需手动清理
db.getUsers()查看当前库的账号与角色
db.getRole("readWrite", { showPrivileges: true })查看内置角色包含的具体权限点
db.adminCommand({ usersInfo: { user: "app", db: "app_db" }, showPrivileges: true })查看账号完整权限清单,排查越权与授权缺失
db.adminCommand({ getParameter: 1, authenticationMechanisms: 1 })查看启用的认证机制(SCRAM-SHA-1/256、MONGODB-X509)
mongod --auth --keyFile /etc/mongo/keyfile --replSet rs0副本集开启认证:内部成员用 keyFile 互信,客户端需账号密码
net.tls.mode: requireTLS 与 net.tls.CAFile在 mongod.conf 中强制 TLS,禁止明文连接
db.adminCommand({ setParameter: 1, authenticationMechanisms: ["SCRAM-SHA-256"] })只保留更安全的认证机制,旧客户端需同步升级
命令 / 语句说明复制
rs.status()副本集总览:成员状态、主节点、复制延迟与选举信息
rs.initiate({ _id: "rs0", members: [{ _id: 0, host: "10.0.0.5:27017", priority: 2 }, { _id: 1, host: "10.0.0.6:27017" }, { _id: 2, host: "10.0.0.7:27017", arbiterOnly: true }] })初始化副本集,仲裁节点只参与投票不存数据
rs.add("10.0.0.6:27017")新增数据成员,会自动触发全量同步
rs.addArb("10.0.0.7:27017")新增仲裁节点,用于凑够奇数票数
rs.remove("10.0.0.6:27017")移除成员,先确认剩余成员满足多数派
rs.conf()查看副本集配置,修改前先导出备份
rs.reconfig(cfg, { force: true })强制重配,仅在多数节点不可用时使用,可能引发回滚
rs.stepDown(60)主动让出主节点 60 秒,用于演练与维护切换
rs.freeze(120)冻结当前节点 120 秒内不参与选举
rs.printReplicationInfo()查看 oplog 大小与可回放时间窗口
rs.printSecondaryReplicationInfo()查看各从节点复制延迟秒数
db.adminCommand({ replSetResizeOplog: 1, size: 20480 })在线把 oplog 调到 20GB(4.0+),缓解从库追不上
db.getSiblingDB("local").oplog.rs.stats().maxSize查看 oplog 实际上限(字节)
sh.status()分片集群总览:分片、数据库与集合的分布情况
sh.addShard("rs1/10.0.0.8:27017")添加分片(以副本集为单位)
sh.enableSharding("app_db")对数据库开启分片能力
sh.shardCollection("app_db.orders", { orderId: "hashed" })哈希分片打散写入热点,范围分片利于范围查询
sh.moveChunk("app_db.orders", { orderId: 1000 }, "rs1")手动迁移数据块,配合均衡器临时关闭做定向调整
sh.setBalancerState(false); sh.getBalancerState(); sh.isBalancerRunning()关闭/查看均衡器状态,业务高峰可临时停均衡
db.adminCommand({ setDefaultRWConcern: 1, defaultWriteConcern: { w: "majority" } })设置默认写关注为多数派,提升故障切换时的数据安全
命令 / 语句说明复制
mongodump --uri="mongodb://app:密码@10.0.0.5:27017/app_db?authSource=admin" --out=/data/backup --gzip逻辑备份整库并压缩,最常用的备份方式
mongodump --uri="mongodb://app:密码@10.0.0.5:27017/app_db?authSource=admin" --collection=users --query="{\"status\":\"active\"}" --out=/data/backup按条件导出单个集合的部分数据
mongodump --uri="mongodb://app:密码@10.0.0.5:27017/?authSource=admin" --oplog --out=/data/backup/full副本集一致性备份,记录备份期间的 oplog
mongodump --uri="mongodb://app:密码@10.0.0.5:27017/app_db?authSource=admin" --archive=/data/backup/app.gz --gzip导出为单文件归档,便于传输与小文件存储
mongodump --uri="mongodb://app:密码@10.0.0.5:27017/app_db?authSource=admin" --gzip --numParallelCollections=4 --out=/data/backup并行导出多个集合,大库可显著缩短备份时间
mongorestore --uri="mongodb://app:密码@10.0.0.5:27017/?authSource=admin" --gzip /data/backup恢复逻辑备份,默认不删除目标库已有数据
mongorestore --uri="mongodb://app:密码@10.0.0.5:27017/?authSource=admin" --nsInclude="app_db.users" --gzip /data/backup只恢复指定命名空间的集合
mongorestore --uri="mongodb://app:密码@10.0.0.5:27017/?authSource=admin" --drop --gzip /data/backup恢复前先删除同名集合(危险,务必确认目标库)
mongorestore --uri="mongodb://app:密码@10.0.0.5:27017/?authSource=admin" --oplogReplay /data/backup/full配合 --oplog 备份回放增量,实现时间点一致恢复
mongorestore --uri="mongodb://app:密码@10.0.0.5:27017/?authSource=admin" --gzip --archive=/data/backup/app.gz --nsFrom="app_db.*" --nsTo="app_db_bak.*"异库恢复,用于数据核对与演练,避免覆盖生产
mongoexport --uri="mongodb://app:密码@10.0.0.5:27017/app_db?authSource=admin" --collection=users --type=json --out=/data/users.json导出 JSON 文本,适合数据交付与调试
mongoexport --uri="mongodb://app:密码@10.0.0.5:27017/app_db?authSource=admin" --collection=users --type=csv --fields=name,age,city --out=/data/users.csv导出 CSV 给业务方,字段较多时用 --fieldFile
mongoimport --uri="mongodb://app:密码@10.0.0.5:27017/app_db?authSource=admin" --collection=users --type=csv --headerline --file=/data/users.csv导入 CSV,headerline 用首行作为字段名
mongoimport --uri="mongodb://app:密码@10.0.0.5:27017/app_db?authSource=admin" --collection=users --type=json --file=/data/users.json --upsertFields=email按业务键 upsert 导入,重复执行不会产生重复文档
db.fsyncLock()锁定写入并刷盘,用于文件系统快照备份,完成后必须解锁
db.fsyncUnlock()解除写锁,快照结束后立即执行,否则业务全部阻塞
命令 / 语句说明复制
db.currentOp({ secs_running: { $gte: 5 } })筛选运行超过 5 秒的操作,慢请求第一现场
db.currentOp({ "command.find": "users" })只看针对某个集合的查询操作
db.currentOp({ waitingForLock: true })查看正在等锁的操作,定位阻塞源头
db.killOp(123456)终止操作(先用 currentOp 确认 opid 与内容)
db.getSiblingDB("admin").aggregate([{ $currentOp: { allUsers: true } }, { $match: { secs_running: { $gte: 5 } } }])4.0+ 聚合方式查看全用户活动操作
db.setProfilingLevel(1, { slowms: 100 })开启慢查询剖析,超过 100ms 的操作写入 system.profile
db.getProfilingStatus()查看剖析级别与慢查询阈值
db.setProfilingLevel(0)关闭剖析,排障结束后务必关闭避免写放大
db.system.profile.find({ millis: { $gt: 500 } }).sort({ ts: -1 }).limit(10)查看最近超过 500ms 的操作明细
db.system.profile.find().sort({ millis: -1 }).limit(10)按耗时排序找最慢的操作,重点看 planSummary
db.system.profile.find({ planSummary: "COLLSCAN" }).count()统计全集合扫描次数,索引缺失的直接证据
db.serverStatus().connections当前连接数、可用连接数与累计创建数
db.serverStatus().opcounters增删改查累计计数,用于容量与压力评估
db.serverStatus().wiredTiger.cache["maximum bytes configured"]WiredTiger 缓存上限,默认约物理内存 50%
db.serverStatus().wiredTiger.cache["bytes currently in the cache"]当前缓存占用,长期接近上限说明内存吃紧
db.serverStatus().wiredTiger.cache["pages read into cache"]从磁盘读入的页数,持续增长说明缓存命中不足
db.serverStatus().mem查看进程常驻内存与虚拟内存占用
mongostat --uri="mongodb://app:密码@10.0.0.5:27017/?authSource=admin" 5每 5 秒输出一次读写、连接、命中率等指标
mongotop --uri="mongodb://app:密码@10.0.0.5:27017/?authSource=admin" 5按集合查看读写耗时分布,定位热点集合
db.stats(1024 * 1024)库级统计:数据量、索引量与碎片情况
命令 / 语句说明复制
db.adminCommand({ logRotate: 1 })切割日志文件(配合 logrotate 与 kill -SIGUSR1)
db.setLogLevel(1, "query")临时提高 query 组件日志级别,排查慢请求细节
db.setLogLevel(-1)恢复默认日志级别,避免日志量暴涨
db.getLogComponents()查看各日志组件的当前详细级别
db.adminCommand({ getLog: "global" }).log.slice(-50)读取最近 50 行全局日志,无需登录服务器
db.adminCommand({ getCmdLineOpts: 1 })查看实例启动参数与实际生效配置
db.adminCommand({ getParameter: 1, wiredTigerConcurrentReadTransactions: 1 })查看 WiredTiger 并发读事务上限
db.adminCommand({ setParameter: 1, wiredTigerConcurrentWriteTransactions: 8 })调整并发写事务数,写排队严重时可评估上调
db.users.reIndex()重建集合全部索引,索引损坏或空间异常时使用
db.runCommand({ compact: "users" })4.4+ 在线整理集合碎片并释放磁盘空间
db.runCommand({ compact: "users", force: true })强制整理(会阻塞该集合的 CRUD,需安排窗口)
db.adminCommand({ validate: "app_db.users", full: true })服务端校验集合数据与索引一致性
db.version(); db.serverBuildInfo()查看版本与编译信息,确认升级与补丁状态
db.hostInfo()查看主机名、操作系统、内存与 CPU 信息
db.repairDatabase()仅单机模式可用,修复损坏数据前必须先做文件级备份
tail -f /var/log/mongodb/mongod.log | grep -iE "error|fatal|WT_"实时观察错误与 WiredTiger 异常,启动失败必看
db.adminCommand({ listCommands: 1 })列出实例支持的全部命令,确认版本能力边界

运维常用组合

慢操作定位与处置db.currentOp({ secs_running: { $gte: 5 } }) 与 db.killOp(opid)
慢查询剖析db.setProfilingLevel(1, { slowms: 100 }) 与 db.system.profile.find().sort({ millis: -1 }).limit(10)
索引是否命中db.users.find({ name: "tom" }).explain("executionStats") 看 stage 与 totalDocsExamined
一致性备份恢复mongodump --oplog --out=/data/backup/full 与 mongorestore --oplogReplay /data/backup/full
复制集健康巡检rs.status() 与 rs.printReplicationInfo() 与 db.serverStatus().repl
空间回收流程db.users.stats(1024 * 1024) 与 db.runCommand({ compact: "users" })

常见问题排查

1. Authentication failed

账号多建在 admin 库:URI 必须带 authSource=admin,或用 --authenticationDatabase 指定

2. 副本集没有主节点

rs.status() 看 stateStr,多数派不可用时无法选主;先恢复网络与宕机节点,避免盲目 force reconfig

3. 从库一直追不上

rs.printReplicationInfo() 看 oplog 窗口,窗口过短会触发全量同步;可用 replSetResizeOplog 扩容并排查大事务

4. 查询突然变慢

explain("executionStats") 看是否 COLLSCAN、totalDocsExamined 是否远大于返回条数,再补建复合索引

5. 磁盘占用持续增长

db.stats() 与集合 stats() 看 storageSize,优先加 TTL 索引、归档历史数据,再评估 compact 回收空间

6. WiredTiger 缓存吃紧

serverStatus().wiredTiger.cache 看 eviction 与 pages read into cache,必要时扩容内存或拆分实例

共 172 条 MongoDB 命令 · 命令均在 mongosh 中执行,shell 命令需在服务器上运行

关于MongoDB命令速查

在线 MongoDB 命令速查手册,按 mongosh 连接与认证、数据库与集合管理、文档增删改查、查询与聚合管道、索引与执行计划、用户权限与安全、副本集与分片、备份恢复与导入导出、性能诊断与监控、日志维护与故障处理等 10 类场景整理 160+ 条常用命令与运维语句,每条附中文说明与典型写法,支持关键词搜索、分类折叠和一键复制,打开网页即可查阅。涵盖 mongosh URI 连接与 authSource、--eval 与 --file 执行、replicaSet 与 readPreference、TLS 连接、use 与 dropDatabase、createCollection(capped 固定集合、timeseries 时序集合、jsonSchema 校验)、insertOne 与 insertMany、bulkWrite、find 投影与 sort/skip/limit 分页、updateOne 与 updateMany 的 $set/$inc/$addToSet/$pull、replaceOne、findOneAndUpdate、deleteMany、countDocuments、distinct、$match/$group/$unwind/$lookup/$project/$facet/$bucket 聚合管道、createIndex 唯一索引与复合索引与 TTL 索引与文本索引与 2dsphere、getIndexes 与 hideIndex 与 indexStats、explain executionStats 看 COLLSCAN 与 totalDocsExamined、createUser 与 grantRolesToUser 与 usersInfo、rs.status 与 rs.initiate 与 rs.add 与 rs.printReplicationInfo 与 replSetResizeOplog、sh.status 与 shardCollection 哈希分片、mongodump 与 mongorestore 的 --oplog 与 --gzip 与 --nsFrom、mongoexport 与 mongoimport 的 CSV/JSON 导入导出、currentOp 与 killOp、setProfilingLevel 与 system.profile、serverStatus 与 wiredTiger.cache、mongostat 与 mongotop、compact 与 reIndex 与 validate 等。适用于 MongoDB 日常运维、慢查询与全表扫描排查、聚合统计、索引优化、副本集与分片集群维护、备份恢复,以及 DBA 面试与面试真题复习。

核心能力

  • 涵盖 mongosh URI 连接与 authSource、--eval 与 --file 执行、replicaSet 与 readPreference、TLS 连接、use 与 dropDatabase、createCollection(capped 固定集合、timeseries 时序集合、jsonSchema 校验)、insertOne 与 insertMany、bulkWrite、find 投影与 sort/skip/limit 分页、updateOne 与 updateMany 的 $set/$inc/$addToSet/$pull、replaceOne、findOneAndUpdate、deleteMany、countDocuments、distinct、$match/$group/$unwind/$lookup/$project/$facet/$bucket 聚合管道、createIndex 唯一索引与复合索引与 TTL 索引与文本索引与 2dsphere、getIndexes 与 hideIndex 与 indexStats、explain executionStats 看 COLLSCAN 与 totalDocsExamined、createUser 与 grantRolesToUser 与 usersInfo、rs.status 与 rs.initiate 与 rs.add 与 rs.printReplicationInfo 与 replSetResizeOplog、sh.status 与 shardCollection 哈希分片、mongodump 与 mongorestore 的 --oplog 与 --gzip 与 --nsFrom、mongoexport 与 mongoimport 的 CSV/JSON 导入导出、currentOp 与 killOp、setProfilingLevel 与 system.profile、serverStatus 与 wiredTiger.cache、mongostat 与 mongotop、compact 与 reIndex 与 validate 等

适用场景

适用于 MongoDB 日常运维、慢查询与全表扫描排查、聚合统计、索引优化、副本集与分片集群维护、备份恢复,以及 DBA 面试与面试真题复习。MongoDB命令速查全程在浏览器中完成,无需安装插件,可放心用于日常办公与排障。

常见问题

MongoDB命令速查是免费的吗?需要注册或安装吗?
MongoDB命令速查完全免费,无需注册、无需下载安装任何软件,用浏览器打开网页即可直接使用,也不限制使用次数。
MongoDB命令速查支持哪些功能?
涵盖 mongosh URI 连接与 authSource、--eval 与 --file 执行、replicaSet 与 readPreference、TLS 连接、use 与 dropDatabase、createCollection(capped 固定集合、timeseries 时序集合、jsonSchema 校验)、insertOne 与 insertMany、bulkWrite、find 投影与 sort/skip/limit 分页、updateOne 与 updateMany 的 $set/$inc/$addToSet/$pull、replaceOne、findOneAndUpdate、deleteMany、countDocuments、distinct、$match/$group/$unwind/$lookup/$project/$facet/$bucket 聚合管道、createIndex 唯一索引与复合索引与 TTL 索引与文本索引与 2dsphere、getIndexes 与 hideIndex 与 indexStats、explain executionStats 看 COLLSCAN 与 totalDocsExamined、createUser 与 grantRolesToUser 与 usersInfo、rs.status 与 rs.initiate 与 rs.add 与 rs.printReplicationInfo 与 replSetResizeOplog、sh.status 与 shardCollection 哈希分片、mongodump 与 mongorestore 的 --oplog 与 --gzip 与 --nsFrom、mongoexport 与 mongoimport 的 CSV/JSON 导入导出、currentOp 与 killOp、setProfilingLevel 与 system.profile、serverStatus 与 wiredTiger.cache、mongostat 与 mongotop、compact 与 reIndex 与 validate 等。
MongoDB命令速查适合哪些场景使用?
适用于 MongoDB 日常运维、慢查询与全表扫描排查、聚合统计、索引优化、副本集与分片集群维护、备份恢复,以及 DBA 面试与面试真题复习。