MongoDB命令集合

MongoDB shell version: 2.2.1
connecting to: test
> 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.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)        //复制数据库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,<slowms>) 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

> db.test.help()
DBCollection help
db.test.find().help()              //show DBCursor help
db.test.count()                    //统计集合文档数
db.test.copyTo(newColl)      //duplicates collection by copying all documents to newColl; no indexes are copied.
db.test.convertToCapped(maxBytes)   //calls {convertToCapped:'test', size:maxBytes}} command
db.test.dataSize()
db.test.distinct( key )            //eg. db.test.distinct( 'x' )
db.test.drop()                  //删除集合
db.test.dropIndex(name)         //删除指定索引
db.test.dropIndexes()           //删除所有索引
db.test.ensureIndex(keypattern[,options])     //options is an object with these possible fields: name, unique, dropDups
db.test.reIndex()               //重建索引
db.test.find([query],[fields])      //query is an optional query filter. fields is optional set of fields to return. e.g. db.test.find( {x:77} , {name:1, x:1} )
db.test.find(...).count()
db.test.find(...).limit(n)
db.test.find(...).skip(n)
db.test.find(...).sort(...)
db.test.findOne([query])
db.test.findAndModify( { update : ... , remove : bool [, query: {}, sort: {}, 'new': false] } )
db.test.getDB()             //get DB object associated with collection
db.test.getIndexes()
db.test.group( { key : ..., initial: ..., reduce : ...[, cond: ...] } )
db.test.insert(obj)
db.test.mapReduce( mapFunction , reduceFunction , <optional params> )
db.test.remove(query)
db.test.renameCollection( newName , <dropTarget> )     //renames the collection.
db.test.runCommand( name , <options> )     //runs a db command with the given name where the first param is the collection name
db.test.save(obj)
db.test.stats()
db.test.storageSize()         //includes free space allocated to this collection
db.test.totalIndexSize()      //size in bytes of all the indexes
db.test.totalSize()           //storage allocated for all data and indexes
db.test.update(query, object[, upsert_bool, multi_bool])      //instead of two flags, you can pass an object with fields: upsert, multi
db.test.validate( <full> )           //SLOW
db.test.getShardVersion()            //only for use with sharding
db.test.getShardDistribution()       //prints statistics about data distribution in the cluster
db.test.getSplitKeysForChunks( <maxChunkSize> )     //calculates split points over all chunks and returns splitter function
推荐查看:http://www.studyday.net/2011/06/218

转载于:https://my.oschina.net/shineyyl/blog/90828

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值