MongoDB帮助信息:db方法,collection方法
发表于:2025-11-07 作者:千家信息网编辑
千家信息网最后更新 2025年11月07日,mongos> db.help()DB methods:db.addUser(username, password[, readOnly=false])db.adminCommand(nameOrDo
千家信息网最后更新 2025年11月07日MongoDB帮助信息:db方法,collection方法
- mongos> db.help()
- DB methods:
- db.addUser(username, password[, readOnly=false])
- db.adminCommand(nameOrDocument) - switches to 'admin' db, and runs command [ just calls db.runCommand(...) ]
- db.auth(username, password)
- db.cloneDatabase(fromhost)
- db.commandHelp(name) returns the help for the command
- db.copyDatabase(fromdb, todb, fromhost)
- db.createCollection(name, { size : ..., capped : ..., max : ... } )
- db.currentOp() displays currently executing operations in the db
- db.dropDatabase()
- db.eval(func, args) run code server-side
- db.fsyncLock() flush data to disk and lock server for backups
- db.fsyncUnlock() unlocks server following a db.fsyncLock()
- db.getCollection(cname) same as db['cname'] or db.cname
- db.getCollectionNames()
- db.getLastError() - just returns the err msg string
- db.getLastErrorObj() - return full status object
- db.getMongo() get the server connection object
- db.getMongo().setSlaveOk() allow queries on a replication slave server
- db.getName()
- db.getPrevError()
- db.getProfilingLevel() - deprecated
- db.getProfilingStatus() - returns if profiling is on and slow threshold
- db.getReplicationInfo()
- db.getSiblingDB(name) get the db at the same server as this one
- db.hostInfo() get details about the server's host
- db.isMaster() check replica primary status
- db.killOp(opid) kills the current operation in the db
- db.listCommands() lists all the db commands
- db.loadServerScripts() loads all the scripts in db.system.js
- db.logout()
- db.printCollectionStats()
- db.printReplicationInfo()
- db.printShardingStatus()
- db.printSlaveReplicationInfo()
- db.removeUser(username)
- db.repairDatabase()
- db.resetError()
- db.runCommand(cmdObj) run a database command. if cmdObj is a string, turns it into { cmdObj : 1 }
- db.serverStatus()
- db.setProfilingLevel(level,
) 0=off 1=slow 2=all - db.setVerboseShell(flag) display extra information in shell output
- db.shutdownServer()
- db.stats()
- db.version() current version of the server
- mongos>
- mongos> db.myCollection.help()
- DBCollection help
- db.myCollection.find().help() - show DBCursor help
- db.myCollection.count()
- db.myCollection.copyTo(newColl) - duplicates collection by copying all documents to newColl; no indexes are copied.
- db.myCollection.convertToCapped(maxBytes) - calls {convertToCapped:'myCollection', size:maxBytes}} command
- db.myCollection.dataSize()
- db.myCollection.distinct( key ) - e.g. db.myCollection.distinct( 'x' )
- db.myCollection.drop() drop the collection
- db.myCollection.dropIndex(index) - e.g. db.myCollection.dropIndex( "indexName" ) or db.myCollection.dropIndex( { "indexKey" : 1 } )
- db.myCollection.dropIndexes()
- db.myCollection.ensureIndex(keypattern[,options]) - options is an object with these possible fields: name, unique, dropDups
- db.myCollection.reIndex()
- db.myCollection.find([query],[fields]) - query is an optional query filter. fields is optional set of fields to return. e.g. db.myCollection.find( {x:77} , {name:1, x:1} )
- db.myCollection.find(...).count()
- db.myCollection.find(...).limit(n)
- db.myCollection.find(...).skip(n)
- db.myCollection.find(...).sort(...)
- db.myCollection.findOne([query])
- db.myCollection.findAndModify( { update : ... , remove : bool [, query:{}, sort: {}, 'new': false] } )
- db.myCollection.getDB() get DB object associated with collection
- db.myCollection.getIndexes()
- db.myCollection.group( { key : ..., initial: ..., reduce : ...[, cond: ...] } )
- db.myCollection.insert(obj)
- db.myCollection.mapReduce( mapFunction , reduceFunction ,
) - db.myCollection.remove(query)
- db.myCollection.renameCollection( newName ,
) renames the collection. - db.myCollection.runCommand( name ,
) runs a db command with the given name where the first param is the collection name - db.myCollection.save(obj)
- db.myCollection.stats()
- db.myCollection.storageSize() - includes free space allocated to this collection
- db.myCollection.totalIndexSize() - size in bytes of all the indexes
- db.myCollection.totalSize() - storage allocated for all data and indexes
- db.myCollection.update(query, object[, upsert_bool, multi_bool]) - instead of two flags, you can pass an object with fields: upsert, multi
- db.myCollection.validate(
) - SLOW - db.myCollection.getShardVersion() - only for use with sharding
- db.myCollection.getShardDistribution() - prints statistics about data distribution in the cluster
- db.myCollection.getSplitKeysForChunks(
) - calculates split points over all chunks and returns splitter function
e.g.
方法
信息
帮助
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
网站网络安全专项治理
数据库自主可控项目
-网络技术挑战赛题目
派出所网络安全考试简报
Hacher网络技术团队
微信登陆服务器繁忙
河南托管服务器云空间
百安居网络技术有限公司
北京光大视讯网络技术
数据库技术的三个阶段和特点
个人搭建云服务器配置
金融会计收录数据库
服务器账号密码管理方法
服务器端软件开发
智能化网络技术服务操作
运营游戏需要服务器吗
修改数据库中数据的方法
数据库建模面试题
从事危害网络安全活动
商丘软件开发联系方式
大连种子软件开发
服务器的硬件配置要求
游戏服务器时间
ping服务器不通
服务器457
最冷门的软件开发
嵌入式软件开发和芯片
数据库中是否存在视图
网络安全工作工资怎么样
商丘软件开发联系方式