博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
MongoDB命令集合
阅读量:6766 次
发布时间:2019-06-26

本文共 6102 字,大约阅读时间需要 20 分钟。

hot3.png

MongoDB shell version: 2.2.1connecting to: test> helpdb.help()                    help on db methodsdb.mycoll.help()             help on collection methodssh.help()                    sharding helpersrs.help()                    replica set helpershelp admin                   administrative helphelp connect                 connecting to a db helphelp keys                    key shortcutshelp misc                    misc things to knowhelp mr                      mapreduceshow dbs                     show database namesshow collections             show collections in current databaseshow users                   show users in current databaseshow profile                 show most recent system.profile entries with time >= 1msshow logs                    show the accessible logger namesshow log [name]              prints out the last segment of log in memory, 'global' is defaultuse 
  set current database
db.foo.find()                list objects in collection foodb.foo.find( { a : 1 } )     list objects in foo where a == 1it                           result of the last line evaluated; use to further iterateDBQuery.shellBatchSize = x   set default number of items to display on shellexit                         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,
) 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 helpdb.test.find().help() //show DBCursor helpdb.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}} commanddb.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, dropDupsdb.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 collectiondb.test.getIndexes()db.test.group( { key : ..., initial: ..., reduce : ...[, cond: ...] } )db.test.insert(obj)db.test.mapReduce( mapFunction , reduceFunction ,
)db.test.remove(query)db.test.renameCollection( newName ,
) //renames the collection.db.test.runCommand( name ,
) //runs a db command with the given name where the first param is the collection namedb.test.save(obj)db.test.stats()db.test.storageSize() //includes free space allocated to this collectiondb.test.totalIndexSize() //size in bytes of all the indexesdb.test.totalSize() //storage allocated for all data and indexesdb.test.update(query, object[, upsert_bool, multi_bool]) //instead of two flags, you can pass an object with fields: upsert, multidb.test.validate(
) //SLOWdb.test.getShardVersion() //only for use with shardingdb.test.getShardDistribution() //prints statistics about data distribution in the clusterdb.test.getSplitKeysForChunks(
) //calculates split points over all chunks and returns splitter function
推荐查看:http://www.studyday.net/2011/06/218

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

你可能感兴趣的文章
fnb2b分支拉取注意事项
查看>>
电脑上没有iis组件,怎么才能安装iis?
查看>>
项目总结01:JSP mysql SpringMvc下中国省市县三级联动下拉框
查看>>
迁移学习(训练数据少的可怜时的办法)
查看>>
Codeforces 798A - Mike and palindrome
查看>>
[BZOJ 1491][NOI2007]社交网络(Floyd)
查看>>
OrderOnline——数据库设计(已更新)
查看>>
(四)虚拟存储管理器的页面调度
查看>>
苹果官方的图标大小的调整
查看>>
观《构建之法》有感
查看>>
maven环境快速搭建(转)
查看>>
Python高级编程–正则表达式(习题)
查看>>
HDU 5742 It's All In The Mind
查看>>
ubuntu和Windows 下的GIF动图工具
查看>>
Visual Studio2012使用技巧
查看>>
编程思想
查看>>
经典布局样式
查看>>
C#下Emgucv的配置
查看>>
【Java基础】sun.misc.BASE64和Java 8 java.util.Base64区别
查看>>
使用PL/SQL连接Oracle时报错ORA-12541: TNS: 无监听程序
查看>>