博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mongo-help功能
阅读量:6528 次
发布时间:2019-06-24

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

mongo提供了help功能,可以帮助我查看一些命令。下面是示例:

> help

db.help() help on db methods
db.mycoll.help() help on collection methods
rs.help() help on replica set methods
help connect connecting to a db help
help admin administrative help
help misc misc things to know
help mr mapreduce help

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
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
admin
> db.help()
DB methods:
db.addUser(username, password[, readOnly=false])
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 the current operation in the db
db.dropDatabase()
db.eval(func, args) run code server-side
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 this connection to read from the nonmaster member of a replica pair
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.isMaster() check replica primary status
db.killOp(opid) kills the current operation in the db
db.listCommands() lists all the db commands
db.printCollectionStats()
db.printReplicationInfo()
db.printSlaveReplicationInfo()
db.printShardingStatus()
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.shutdownServer()
db.stats()
db.version() current version of the server
db.getMongo().setSlaveOk() allow queries on a replication slave server
> rs.help()
rs.status() { replSetGetStatus : 1 } checks repl set status
rs.initiate() { replSetInitiate : null } initiates set with default settings
rs.initiate(cfg) { replSetInitiate : cfg } initiates set with configuration cfg
rs.conf() get the current configuration object from local.system.replset
rs.reconfig(cfg) updates the configuration of a running replica set with cfg (disconnects)
rs.add(hostportstr) add a new member to the set with default attributes (disconnects)
rs.add(membercfgobj) add a new member to the set with extra attributes (disconnects)
rs.addArb(hostportstr) add a new member which is arbiterOnly:true (disconnects)
rs.stepDown([secs]) step down as primary (momentarily) (disconnects)
rs.freeze(secs) make a node ineligible to become primary for the time specified
rs.remove(hostportstr) remove a host from the replica set (disconnects)
rs.slaveOk() shorthand for db.getMongo().setSlaveOk()

db.isMaster() check who is primary

reconfiguration helpers disconnect from the database so the shell will display

an error, even if the command succeeds.
see also http://<mongod_host>:28017/_replSet for additional diagnostic info
> db
admin
> show collections
settings
system.indexes
> db.settings.help()
DBCollection help
db.settings.find().help() - show DBCursor help
db.settings.count()
db.settings.dataSize()
db.settings.distinct( key ) - eg. db.settings.distinct( 'x' )
db.settings.drop() drop the collection
db.settings.dropIndex(name)
db.settings.dropIndexes()
db.settings.ensureIndex(keypattern[,options]) - options is an object with these possible fields: name, unique, dropDups
db.settings.reIndex()
db.settings.find([query],[fields]) - query is an optional query filter. fields is optional set of fields to return.
e.g. db.settings.find( {x:77} , {name:1, x:1} )
db.settings.find(...).count()
db.settings.find(...).limit(n)
db.settings.find(...).skip(n)
db.settings.find(...).sort(...)
db.settings.findOne([query])
db.settings.findAndModify( { update : ... , remove : bool [, query: {}, sort: {}, 'new': false] } )
db.settings.getDB() get DB object associated with collection
db.settings.getIndexes()
db.settings.group( { key : ..., initial: ..., reduce : ...[, cond: ...] } )
db.settings.mapReduce( mapFunction , reduceFunction , <optional params> )
db.settings.remove(query)
db.settings.renameCollection( newName , <dropTarget> ) renames the collection.
db.settings.runCommand( name , <options> ) runs a db command with the given name where the first param is the collection name
db.settings.save(obj)
db.settings.stats()
db.settings.storageSize() - includes free space allocated to this collection
db.settings.totalIndexSize() - size in bytes of all the indexes
db.settings.totalSize() - storage allocated for all data and indexes
db.settings.update(query, object[, upsert_bool, multi_bool])
db.settings.validate() - SLOW
db.settings.getShardVersion() - only for use with sharding
>

 

如果在输入函数的时候,不加上左右括号会怎么样呢?注意看mongo提示出来的是这个函数的JS源码。通过这个小技巧,你可以了解这个函数的实现方法,以及它的参数及顺序:

> db.settings.insert

function (obj, _allow_dot) {
if (!obj) {
throw "no object passed to insert!";
}
if (!_allow_dot) {
this._validateForStorage(obj);
}
if (typeof obj._id == "undefined") {
var tmp = obj;
obj = {_id:new ObjectId};
for (var key in tmp) {
obj[key] = tmp[key];
}
}
this._mongo.insert(this._fullName, obj);
this._lastID = obj._id;
}

转载地址:http://ratbo.baihongyu.com/

你可能感兴趣的文章
函数指针和指针函数
查看>>
认识配置设置文件(INI与XML)
查看>>
DZ!NT论坛 3.6.711删除用户各种错解决方案
查看>>
Python的函数参数传递:传值?引用?
查看>>
[转]分享2011年8个最新的jQuery Mobile在线教程
查看>>
android call require api level
查看>>
Mac下android环境搭建
查看>>
创建Visual Studio项目模版向导的几篇参考文章
查看>>
深入浅出SQL Server Replication第一篇:走近Replication(上)
查看>>
[TopCoder][SRM] SRM 562 DIV 2
查看>>
SQLSERVER是怎麽通过索引和统计信息来找到目标数据的(第一篇)
查看>>
LocalAlloc,VirtualAlloc,malloc,new的异同
查看>>
回调函数
查看>>
win7 x64 jdk1.7.0_51
查看>>
45 Useful Oracle Queries--ref
查看>>
这些开源项目,你都知道吗?(持续更新中...)[原创]
查看>>
linux中利用iptables+geoip过滤指定IP
查看>>
在myeclipse中写sql语句的细节问题
查看>>
使用ShellExecute打开目标文件所在文件夹并选中目标文件
查看>>
Lombok简化Java代码的好工具
查看>>