mongodb中帮助信息和命令

在Mongodb中,可以看作是一种面向对象的操作,如果你对与某一个操作不清楚,可以直接help。

在mongodb中,无非是对DB、user、collections、文档的操作。

下面是简单的示例:

现在我不知道db该如何操作:

> show dbs;
admin    0.000GB
ikidana  0.000GB
local    0.000GB
> db.ikidana.help()
DBCollection help
    db.ikidana.find().help() - show DBCursor help
    db.ikidana.bulkWrite( operations, <optional params> ) - bulk execute write operations, optional parameters are: w, wtimeout, j
    db.ikidana.count( query = {}, <optional params> ) - count the number of documents that matches the query, optional parameters are: limit, skip, hint, maxTimeMS
    ......

我不知道user有哪些操作可以这样:

> show users;
{
    "_id" : "ikidana.yueji",
    "userId" : BinData(4,"OIbrRRo+QwmhZmw2ECekPQ=="),
    "user" : "yueji",
    "db" : "ikidana",
    "roles" : [
        {
            "role" : "readWrite",
            "db" : "ikidana"
        }
    ]
}
> db.user.yueji.help()
DBCollection help
    db.user.yueji.find().help() - show DBCursor help
    db.user.yueji.bulkWrite( operations, <optional params> ) - bulk execute write operations, optional parameters are: w, wtimeout, j
    db.user.yueji.count( query = {}, <optional params> ) - count the number of documents that matches the query, optional parameters are: limit, skip, hint, maxTimeMS
        ......

> db.user.help()
DBCollection help
    db.user.find().help() - show DBCursor help
    db.user.bulkWrite( operations, <optional params> ) - bulk execute write operations, optional parameters are: w, wtimeout, j
    db.user.count( query = {}, <optional params> ) - count the number of documents that matches the query, optional parameters are: limit, skip, hint, maxTimeMS
         ......

对于聚集集合也可以这样:

> show collections
blog
info
test
yue-test
> db.blog.help()
DBCollection help
    db.blog.find().help() - show DBCursor help
    db.blog.bulkWrite( operations, <optional params> ) - bulk execute write operations, optional parameters are: w, wtimeout, j
    db.blog.count( query = {}, <optional params> ) - count the number of documents that matches the query, optional parameters are: limit, skip, hint, maxTimeMS
    db.blog.copyTo(newColl) - duplicates collection by copying all documents to newColl; no indexes are copied.
        ......

 

下面是一些常规的帮助信息:

通过help可以查看所有的帮助信息:

> help
    db.help()                    查看DB的帮助信息
    db.mycoll.help()             查看collection的帮助信息
    sh.help()                    查看sharding(分片)的帮助信息
    rs.help()                    查看replica set(副本集)的帮助信息
    help admin                   管理员管理帮助
    help connect                 DB连接帮助
    help keys                    快捷键
    help misc                    misc things to know
    help mr                      mapreduce

    show dbs                     显示数据库名称
    show collections             显示当前数据库中的集合
    show users                   显示当前数据库中的用户
    show profile                 显示最新的system.profile条目,时间> = 1ms
    show logs                    显示可访问的日志名称
    show log [name]              打印出内存中最后一段日志,'global'是默认值
    use <db_name>                切换/创建数据库
    db.foo.find()                列出集合foo中的对象
    db.foo.find( { a : 1 } )     列出foo中的对象,其中a == 1
    it                           评估最后一行的结果; 用来进一步迭代
    DBQuery.shellBatchSize = x   设置要在shell上显示的默认项目数
    exit                         退出

 

DB相关的帮助信息:

    db.adminCommand(nameOrDocument):切换到admin数据库,并运行命令(只调用db.runCommand(...))
    db.auth(username, password):用户名密码验证
    db.cloneDatabase(fromhost):从指定机器上克隆数据库到当前数据库
    db.commandHelp(name):返回该命令的帮助信息
    db.copyDatabase(fromdb, todb, fromhost):将本机上的数据库复制到目标机器上
    db.createCollection(name, { size : ..., capped : ..., max : ... } ):创建一个聚集集合
    db.createView(name, viewOn, [ { $operator: {...}}, ... ], { viewOptions } ):创建视图
    db.createUser(userDocument)#创建一个用户
    db.currentOp():显示当前在db中执行的操作
    db.dropDatabase():删除一个数据库
    db.fsyncLock():将数据刷新到磁盘并锁定服务器以进行备份
    db.fsyncUnlock():在db.fsyncLock()之后解锁服务器
    db.getCollection(cname):得到指定名称的聚集集合,与db ['cname']或db.cname相同
    db.getCollectionInfos([filter]):返回一个包含db集合的名称和选项的列表
    db.getCollectionNames():得到当前db的所有聚集集合
    db.getLastError():只返回错误的msg字符串
    db.getLastErrorObj():返回完整状态对象
    db.getLogComponents():返回日志消息详细级别
    db.getMongo():获取服务器连接对象
    db.getMongo().setSlaveOk():允许在复制从属服务器上进行查询
    db.getName():查询当前使用的数据库
    db.getPrevError():查询之前的错误信息
    db.getProfilingStatus():如果分析处于打开状态且缓慢阈值则返回
    db.getReplicationInfo():查看oplog的状态、大小、存储的时间范围
    db.getSiblingDB(name):在与此服务器相同的服务器上获取db
    db.getWriteConcern():返回用于此db上的任何操作的写入关注点,如果设置,则从服务器对象继承
    db.hostInfo():获取有关服务器主机的详细信息
    db.isMaster():检查副本主要状态
    db.killOp(opid):终止db中的当前操作
    db.listCommands():列出了所有db命令
    db.loadServerScripts():加载db.system.js中的所有脚本
    db.printCollectionStats():现实当前DB所有聚集索引的状态
    db.printReplicationInfo():
    db.printShardingStatus():
    db.printSlaveReplicationInfo():
    db.dropUser(username):
    db.repairDatabase():
    db.resetError():
    db.runCommand(cmdObj):运行数据库命令。如果cmdObj是一个字符串,则将其转换为{cmdObj:1}
    db.serverStatus():
    db.setLogLevel(level,<component>)
    db.setProfilingLevel(level,<slowms>) 0=off 1=slow 2=all
    db.setWriteConcern( <write concern doc> ):设置写入db的写入问题
    db.unsetWriteConcern( <write concern doc> ):取消写入db的写入问题
    db.setVerboseShell(flag):在shell输出中显示额外信息
    db.shutdownServer()
    db.stats():显示当前db状态
    db.version():服务器的当前版本

 

posted @ 2019-08-01 11:06  明王不动心  阅读(764)  评论(0编辑  收藏  举报