重庆思庄Oracle、Redhat认证学习论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 751|回复: 0
打印 上一主题 下一主题

MONGODB查看帮忙命令

[复制链接]
跳转到指定楼层
楼主
发表于 2023-10-6 18:09:26 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
--server级别
> help
        db.help()                    help on db methods
        db.mycoll.help()             help on collection methods
        sh.help()                    sharding helpers
        rs.help()                    replica set helpers
        help admin                   administrative help
        help connect                 connecting to a db help
        help keys                    key shortcuts
        help misc                    misc things to know
        help mr                      mapreduce

        show dbs                     show database names
        show collections             show collections in current database
        show users                   show users in current database
        show profile                 show most recent system.profile entries with time >= 1ms
        show logs                    show the accessible logger names
        show log [name]              prints out the last segment of log in memory, 'global' is default
        use <db_name>                set current database
        db.foo.find()                list objects in collection foo
        db.foo.find( { a : 1 } )     list objects in foo where a == 1
        it                           result of the last line evaluated; use to further iterate
        DBQuery.shellBatchSize = x   set default number of items to display on shell
        exit                         quit the mongo shell


--db级别
> db.help();
DB methods:
        db.adminCommand(nameOrDocument) - switches to 'admin' db, and runs command [just calls db.runCommand(...)]
        db.aggregate([pipeline], {options}) - performs a collectionless aggregation on this database; returns a cursor
        db.auth(username, password)
        db.cloneDatabase(fromhost) - will only function with MongoDB 4.0 and below
        db.commandHelp(name) returns the help for the command
        db.copyDatabase(fromdb, todb, fromhost) - will only function with MongoDB 4.0 and below
        db.createCollection(name, {size: ..., capped: ..., max: ...})
        db.createUser(userDocument)
        db.createView(name, viewOn, [{$operator: {...}}, ...], {viewOptions})
        db.currentOp() displays currently executing operations in the db
        db.dropDatabase(writeConcern)
        db.dropUser(username)
        db.eval() - deprecated
        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.getCollectionInfos([filter]) - returns a list that contains the names and options of the db's collections
        db.getCollectionNames()
        db.getLastError() - just returns the err msg string
        db.getLastErrorObj() - return full status object
        db.getLogComponents()
        db.getMongo() get the server connection object
        db.getMongo().setSecondaryOk() allow queries on a replication secondary server
        db.getName()
        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.getWriteConcern() - returns the write concern used for any operations on this db, inherited from server object if set
        db.hostInfo() get details about the server's host
        db.isMaster() check replica primary status
        db.hello() 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.printSecondaryReplicationInfo()
        db.resetError()
        db.runCommand(cmdObj) run a database command.  if cmdObj is a string, turns it into {cmdObj: 1}
        db.serverStatus()
        db.setLogLevel(level,<component>)
        db.setProfilingLevel(level,slowms) 0=off 1=slow 2=all
        db.setVerboseShell(flag) display extra information in shell output
        db.setWriteConcern(<write concern doc>) - sets the write concern for writes to the db
        db.shutdownServer()
        db.stats()
        db.unsetWriteConcern(<write concern doc>) - unsets the write concern for writes to the db
        db.version() current version of the server
        db.watch() - opens a change stream cursor for a database to report on all  changes to its non-system collections.
>

--集合级别

> db.employees.help()
DBCollection help
        db.employees.find().help() - show DBCursor help
        db.employees.bulkWrite( operations, <optional params> ) - bulk execute write operations, optional parameters are: w, wtimeout, j
        db.employees.count( query = {}, <optional params> ) - count the number of documents that matches the query, optional parameters are: limit, skip, hint, maxTimeMS
        db.employees.countDocuments( query = {}, <optional params> ) - count the number of documents that matches the query, optional parameters are: limit, skip, hint, maxTimeMS
        db.employees.estimatedDocumentCount( <optional params> ) - estimate the document count using collection metadata, optional parameters are: maxTimeMS
        db.employees.convertToCapped(maxBytes) - calls {convertToCapped:'employees', size:maxBytes}} command
        db.employees.createIndex(keypattern[,options])
        db.employees.createIndexes([keypatterns], <options>)
        db.employees.dataSize()
        db.employees.deleteOne( filter, <optional params> ) - delete first matching document, optional parameters are: w, wtimeout, j
        db.employees.deleteMany( filter, <optional params> ) - delete all matching documents, optional parameters are: w, wtimeout, j
        db.employees.distinct( key, query, <optional params> ) - e.g. db.employees.distinct( 'x' ), optional parameters are: maxTimeMS
        db.employees.drop() drop the collection
        db.employees.dropIndex(index) - e.g. db.employees.dropIndex( "indexName" ) or db.employees.dropIndex( { "indexKey" : 1 } )
        db.employees.dropIndexes()
        db.employees.ensureIndex(keypattern[,options]) - DEPRECATED, use createIndex() instead
        db.employees.explain().help() - show explain help
        db.employees.reIndex()
        db.employees.find([query],[fields]) - query is an optional query filter. fields is optional set of fields to return.
                                                      e.g. db.employees.find( {x:77} , {name:1, x:1} )
        db.employees.find(...).count()
        db.employees.find(...).limit(n)
        db.employees.find(...).skip(n)
        db.employees.find(...).sort(...)
        db.employees.findOne([query], [fields], [options], [readConcern])
        db.employees.findOneAndDelete( filter, <optional params> ) - delete first matching document, optional parameters are: projection, sort, maxTimeMS
        db.employees.findOneAndReplace( filter, replacement, <optional params> ) - replace first matching document, optional parameters are: projection, sort, maxTimeMS, upsert, returnNewDocument
        db.employees.findOneAndUpdate( filter, <update object or pipeline>, <optional params> ) - update first matching document, optional parameters are: projection, sort, maxTimeMS, upsert, returnNewDocument
        db.employees.getDB() get DB object associated with collection
        db.employees.getPlanCache() get query plan cache associated with collection
        db.employees.getIndexes()
        db.employees.insert(obj)
        db.employees.insertOne( obj, <optional params> ) - insert a document, optional parameters are: w, wtimeout, j
        db.employees.insertMany( [objects], <optional params> ) - insert multiple documents, optional parameters are: w, wtimeout, j
        db.employees.mapReduce( mapFunction , reduceFunction , <optional params> )
        db.employees.aggregate( [pipeline], <optional params> ) - performs an aggregation on a collection; returns a cursor
        db.employees.remove(query)
        db.employees.replaceOne( filter, replacement, <optional params> ) - replace the first matching document, optional parameters are: upsert, w, wtimeout, j
        db.employees.renameCollection( newName , <dropTarget> ) renames the collection.
        db.employees.runCommand( name , <options> ) runs a db command with the given name where the first param is the collection name
        db.employees.save(obj)
        db.employees.stats({scale: N, indexDetails: true/false, indexDetailsKey: <index key>, indexDetailsName: <index name>})
        db.employees.storageSize() - includes free space allocated to this collection
        db.employees.totalIndexSize() - size in bytes of all the indexes
        db.employees.totalSize() - storage allocated for all data and indexes
        db.employees.update( query, <update object or pipeline>[, upsert_bool, multi_bool] ) - instead of two flags, you can pass an object with fields: upsert, multi, hint
        db.employees.updateOne( filter, <update object or pipeline>, <optional params> ) - update the first matching document, optional parameters are: upsert, w, wtimeout, j, hint
        db.employees.updateMany( filter, <update object or pipeline>, <optional params> ) - update all matching documents, optional parameters are: upsert, w, wtimeout, j, hint
        db.employees.validate( <full> ) - SLOW
        db.employees.getShardVersion() - only for use with sharding
        db.employees.getShardDistribution() - prints statistics about data distribution in the cluster
        db.employees.getSplitKeysForChunks( <maxChunkSize> ) - calculates split points over all chunks and returns splitter function
        db.employees.getWriteConcern() - returns the write concern used for any operations on this collection, inherited from server/db if set
        db.employees.setWriteConcern( <write concern doc> ) - sets the write concern for writes to the collection
        db.employees.unsetWriteConcern( <write concern doc> ) - unsets the write concern for writes to the collection
        db.employees.latencyStats() - display operation latency histograms for this collection

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 支持支持 反对反对
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|手机版|小黑屋|重庆思庄Oracle、Redhat认证学习论坛 ( 渝ICP备12004239号-4 )

GMT+8, 2024-11-16 10:51 , Processed in 0.082850 second(s), 19 queries .

重庆思庄学习中心论坛-重庆思庄科技有限公司论坛

© 2001-2020

快速回复 返回顶部 返回列表