MongoDB's avaliable commands

本文涉及的产品
云数据库 MongoDB,通用型 2核4GB
简介:
命令是mongoDB中一个比较特殊的操作。
在mongoDB中执行命令有两种常用的方法,
1. runCommand({$key : $value})
如:
> db.runCommand({"shutdown" : 1})

2. 查询$cmd这个特殊的collection
如:
> db.$cmd.findOne({"shutdown" : 1})

列出当前mongoDB中可以支持的命令,可以通过调用db.listCommands()或者是查看浏览器 run “mongod --rest” and then visit http://localhost:28017/_commands in your web browser.
如:
> db.listCommands()
_recvChunkCommit: no-lock adminOnly  slaveOk 
  internal should not be calling this directly
  

_recvChunkStart: write-lock adminOnly  slaveOk 
  internal should not be calling this directly
  

_recvChunkStatus: no-lock adminOnly  slaveOk 
  internal should not be calling this directly
  

_testDistLockWithSyncCluster: no-lock adminOnly  slaveOk 
  should not be calling this directly
  

_transferMods: no-lock adminOnly  slaveOk 
  internal should not be calling this directly
  

applyOps: write-lock
  examples: { applyOps : [ ] , preCondition : [ { ns : ... , q : ... , res : ... } ] }

assertInfo: write-lock
  check if any asserts have occurred on the server

authenticate: write-lock
  internal

availablequeryoptions: no-lock
  no help defined

buildInfo: no-lock adminOnly  slaveOk 
  get version #, etc.
  { buildinfo:1 }

captrunc: write-lock
  no help defined

clean: write-lock
  internal

clone: write-lock
  clone this database from an instance of the db on another host
  { clone : "host13" }

cloneCollection: no-lock
  { cloneCollection: <namespace>, from: <host> [,query: <query_filter>] [,copyIndexes:<bool>] }
  Copies a collection from one server to another. Do not use on a single server as the destination is placed at the same db.collection (namespace) as the source.
  Warning: the local copy of 'ns' is emptied before the copying begins. Any existing data will be lost there.

cloneCollectionAsCapped: write-lock
  { cloneCollectionAsCapped:<fromName>, toCollection:<toName>, size:<sizeInBytes> }

closeAllDatabases: write-lock adminOnly  slaveOk 
  Close all database files.
  A new request will cause an immediate reopening; thus, this is mostly for testing purposes.

collStats: read-lock
  { collStats:"blog.posts" , scale : 1 } scale divides sizes e.g. for KB use 1024

connPoolStats: no-lock
  stats about connection pool

connPoolSync: no-lock
  internal

convertToCapped: write-lock
  { convertToCapped:<fromCollectionName>, size:<sizeInBytes> }

copydb: write-lock adminOnly  slaveOk 
  copy a database from another host to this host
  usage: {copydb: 1, fromhost: <hostname>, fromdb: <db>, todb: <db>[, username: <username>, nonce: <nonce>, key: <key>]}

copydbgetnonce: write-lock adminOnly  slaveOk 
  get a nonce for subsequent copy db request from secure server
  usage: {copydbgetnonce: 1, fromhost: <hostname>}

count: read-lock
  count objects in collection

create: write-lock
  create a collection

cursorInfo: no-lock
   example: { cursorInfo : 1 }

dataSize: read-lock
  determine data size for a set of data in a certain range
  example: { datasize:"blog.posts", keyPattern:{x:1}, min:{x:10}, max:{x:55} }
  keyPattern, min, and max parameters are optional.
  note: This command may take a while to run

dbHash: read-lock
  no help defined

dbStats: read-lock
   example: { dbstats:1 } 

diagLogging: write-lock adminOnly  slaveOk 
  http://www.mongodb.org/display/DOCS/Monitoring+and+Diagnostics#MonitoringandDiagnostics-DatabaseRecord%2FReplay

distinct: read-lock
  { distinct : 'collection name' , key : 'a.b' , query : {} }

driverOIDTest: no-lock
  no help defined

drop: write-lock
  drop a collection
  {drop : <collectionName>}

dropDatabase: write-lock
  drop (delete) this database

dropIndexes: write-lock
  drop indexes for a collection

emptycapped: write-lock
  no help defined

eval: no-lock
  Evaluate javascript at the server.
  http://www.mongodb.org/display/DOCS/Server-side+Code+Execution

features: read-lock
  return on build level feature settings

filemd5: read-lock
   example: { filemd5 : ObjectId(aaaaaaa) , root : "fs" }

findAndModify: write-lock
  { findandmodify: "collection", query: {processed:false}, update: {$set: {processed:true}}, new: true}
  { findandmodify: "collection", query: {processed:false}, remove: true, sort: {priority:-1}}
  Either update or remove is required, all other fields have default values.
  Output is in the "value" field
  

forcedead: write-lock adminOnly  slaveOk 
  internal

forceerror: no-lock
  for testing purposes only.  forces a user assertion exception

fsync: write-lock adminOnly  slaveOk 
  http://www.mongodb.org/display/DOCS/fsync+Command

geoNear: read-lock
  http://www.mongodb.org/display/DOCS/Geospatial+Indexing#GeospatialIndexing-geoNearCommand

geoSearch: read-lock
  no help defined

geoWalk: read-lock
  no help defined

getCmdLineOpts: no-lock adminOnly  slaveOk 
  get argv

getLastError: no-lock
  return error status of the last operation on this connection

getPrevError: no-lock
  check for errors since last reseterror commandcal

getShardVersion: no-lock adminOnly  slaveOk 
   example: { getShardVersion : 'alleyinsider.foo'  } 

getnonce: no-lock
  internal

getoptime: no-lock
  internal

godinsert: write-lock
  internal. for testing only.

group: read-lock
  http://www.mongodb.org/display/DOCS/Aggregation

handshake: no-lock
  internal

isMaster: no-lock
  Check if this server is primary for a replica pair/set; also if it is --master or --slave in simple master/slave setups.
  { isMaster : 1 }

isinitialsynccomplete: write-lock
  no help defined

listCommands: no-lock
  get a list of all db commands

listDatabases: read-lock adminOnly  slaveOk 
  list databases on this server

logRotate: no-lock adminOnly  slaveOk 
  no help defined

logout: no-lock
  de-authenticate

mapReduce: no-lock
  Run a map/reduce operation on the server.
  Note this is used for aggregation, not querying, in MongoDB.
  http://www.mongodb.org/display/DOCS/MapReduce

mapreduce.shardedfinish: no-lock
  no help defined

medianKey: read-lock
  Internal command.
  example: { medianKey:"blog.posts", keyPattern:{x:1}, min:{x:10}, max:{x:55} }
  NOTE: This command may take a while to run

moveChunk: no-lock adminOnly  slaveOk 
  should not be calling this directly
  

negotiatemaster: write-lock adminOnly  slaveOk 
  no help defined

ping: no-lock
  a way to check that the server is alive. responds immediately even if server is in a db lock.

profile: write-lock
  enable or disable performance profiling
  { profile : <n> }
  0=off 1=log slow ops 2=log all
  http://www.mongodb.org/display/DOCS/Database+Profiler

reIndex: write-lock
  re-index a collection

renameCollection: write-lock adminOnly  slaveOk 
   example: { renameCollection: foo.a, to: bar.b }

repairDatabase: write-lock
  repair database.  also compacts. note: slow.

replSetElect: no-lock adminOnly  slaveOk 
  internal

replSetFreeze: no-lock adminOnly  slaveOk 
  Enable / disable failover for the set - locks current primary as primary even if issues occur.
  For use during system maintenance.
  { replSetFreeze : <bool> }
  http://www.mongodb.org/display/DOCS/Replica+Set+Commands

replSetFresh: no-lock adminOnly  slaveOk 
  internal

replSetGetRBID: no-lock adminOnly  slaveOk 
  internal

replSetGetStatus: no-lock adminOnly  slaveOk 
  Report status of a replica set from the POV of this server
  { replSetGetStatus : 1 }
  http://www.mongodb.org/display/DOCS/Replica+Set+Commands

replSetHeartbeat: no-lock
  internal

replSetInitiate: no-lock adminOnly  slaveOk 
  Initiate/christen a replica set.
  http://www.mongodb.org/display/DOCS/Replica+Set+Commands

replSetReconfig: no-lock adminOnly  slaveOk 
  Adjust configuration of a replica set
  { replSetReconfig : config_object }
  http://www.mongodb.org/display/DOCS/Replica+Set+Commands

replSetStepDown: no-lock adminOnly  slaveOk 
  Step down as primary.  Will not try to reelect self or 1 minute.
  (If another member with same priority takes over in the meantime, it will stay primary.)
  http://www.mongodb.org/display/DOCS/Replica+Set+Commands

replSetTest: no-lock adminOnly  slaveOk 
  Just for regression tests.
  

replacePeer: write-lock adminOnly  slaveOk 
  replace a node in a replica pair

resetError: no-lock
  reset error state (used with getpreverror)

resync: write-lock adminOnly  slaveOk 
  resync (from scratch) an out of date replica slave.
  http://www.mongodb.org/display/DOCS/Master+Slave

serverStatus: no-lock
  returns lots of administrative server statistics

setShardVersion: write-lock adminOnly  slaveOk 
   example: { setShardVersion : 'alleyinsider.foo' , version : 1 , configdb : '' } 

shardingState: write-lock adminOnly  slaveOk 
  no help defined

shutdown: write-lock adminOnly  slaveOk 
  shutdown the database.  must be ran against admin db and either (1) ran from localhost or (2) authenticated.
  

sleep: no-lock adminOnly  slaveOk 
  internal testing command.  Makes db block (in a read lock) for 100 seconds
  w:true write lock

splitVector: read-lock
  Internal command.
  example: { splitVector : "myLargeCollection" , keyPattern : {x:1} , maxChunkSize : 200 }
  maxChunkSize unit in MBs
  NOTE: This command may take a while to run

top: read-lock adminOnly  slaveOk 
  usage by collection

unsetSharding: no-lock adminOnly  slaveOk 
   example: { unsetSharding : 1 } 

validate: read-lock
  Validate contents of a namespace by scanning its data structures for correctness.  Slow.

whatsmyuri: no-lock
  {whatsmyuri:1}

writebacklisten: no-lock adminOnly  slaveOk 
  internal
相关实践学习
MongoDB数据库入门
MongoDB数据库入门实验。
快速掌握 MongoDB 数据库
本课程主要讲解MongoDB数据库的基本知识,包括MongoDB数据库的安装、配置、服务的启动、数据的CRUD操作函数使用、MongoDB索引的使用(唯一索引、地理索引、过期索引、全文索引等)、MapReduce操作实现、用户管理、Java对MongoDB的操作支持(基于2.x驱动与3.x驱动的完全讲解)。 通过学习此课程,读者将具备MongoDB数据库的开发能力,并且能够使用MongoDB进行项目开发。 &nbsp; 相关的阿里云产品:云数据库 MongoDB版 云数据库MongoDB版支持ReplicaSet和Sharding两种部署架构,具备安全审计,时间点备份等多项企业能力。在互联网、物联网、游戏、金融等领域被广泛采用。 云数据库MongoDB版(ApsaraDB for MongoDB)完全兼容MongoDB协议,基于飞天分布式系统和高可靠存储引擎,提供多节点高可用架构、弹性扩容、容灾、备份回滚、性能优化等解决方案。 产品详情: https://www.aliyun.com/product/mongodb
相关文章
|
4月前
|
NoSQL MongoDB 数据库
MongoDB 命令
MongoDB 命令
|
10月前
|
存储 JSON NoSQL
【BackEnd--Mongodb】学习笔记(完整详细版)
MongoDB是一种面向文档的非关系型数据库,所谓的面向文档是一种类似JSON的结构,因此可以简单理解MongoDB存储的是各种各样的JSONMongoDB可以快速开发web型应用,因为存储的是JSON格式,因此无需像关系型数据库那样需要建表,非常的的灵活。
187 0
|
NoSQL MongoDB
MongoDB:15-MongoDB- $isolate
MongoDB:15-MongoDB- $isolate
118 0
|
存储 SQL NoSQL
logstash-output-mongodb实现Mysql到Mongodb数据同步
本文主要讲解如何通过logstash-output-mongodb插件实现Mysql与Mongodb数据的同步。源数据存储在Mysql,目标数据库为非关系型数据库Mongodb。
377 0
|
NoSQL MongoDB 数据安全/隐私保护
Mongodb日常使用命令
mongodb,权限
1024 0
|
NoSQL 数据库 MongoDB
|
索引 NoSQL MongoDB
|
NoSQL 数据库
Six Reasons to Embrace MongoDB 3.x Over MongoDB 2.x
Are you still deciding if you should upgrade to the next MongoDB version? This article is lists five reasons why we think you should switch from MongoDB 2.
2434 0
|
SQL NoSQL MongoDB
MongoDB - basic
mongoDB basic from:http://www.tutorialspoint.com/mongodb prject:https://github.com/chenxing12/l4mongodb overview getting-start collection dataType in...
845 0