美文网首页
MongoDB开发之 Shell其他特性

MongoDB开发之 Shell其他特性

作者: 五月笙 | 来源:发表于2020-12-24 16:58 被阅读0次

运行

$ mongo
MongoDB shell version v4.0.10
connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("1f3d0d3a-5bb2-4e93-8dc5-5dcd037d651a") }
MongoDB server version: 4.0.10
>

help

MongoDB Shell 内置了帮助文档。

> 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
>

db.help()是数据库级别的帮助文档:

> db.help()
DB methods:
    db.adminCommand(nameOrDocument) - switches to 'admin' db, and runs command [just calls db.runCommand(...)]
    db.aggregate([pipeline], {options}) - performs a collectionless aggregation on this database; returns a cursor
    db.auth(username, password)
    db.cloneDatabase(fromhost) - deprecated
    db.commandHelp(name) returns the help for the command
    db.copyDatabase(fromdb, todb, fromhost) - deprecated
    db.createCollection(name, {size: ..., capped: ..., max: ...})
    db.createView(name, viewOn, [{$operator: {...}}, ...], {viewOptions})
    db.createUser(userDocument)
    db.currentOp() displays currently executing operations in the db
    db.dropDatabase()
    ...
>

db.{collection}.help()查看集合级别的帮助文档:

> use machine
switched to db machine
> db.machine.help()
DBCollection help
    db.machine.find().help() - show DBCursor help
    db.machine.bulkWrite( operations, <optional params> ) - bulk execute write operations, optional parameters are: w, wtimeout, j
    db.machine.count( query = {}, <optional params> ) - count the number of documents that matches the query, optional parameters are: limit, skip, hint, maxTimeMS
    db.machine.countDocuments( query = {}, <optional params> ) - count the number of documents that matches the query, optional parameters are: limit, skip, hint, maxTimeMS
    db.machine.estimatedDocumentCount( <optional params> ) - estimate the document count using collection metadata, optional parameters are: maxTimeMS
    db.machine.copyTo(newColl) - duplicates collection by copying all documents to newColl; no indexes are copied.
    db.machine.convertToCapped(maxBytes) - calls {convertToCapped:'machine', size:maxBytes}} command
    db.machine.createIndex(keypattern[,options])
    db.machine.createIndexes([keypatterns], <options>)
    db.machine.dataSize()
    db.machine.deleteOne( filter, <optional params> ) - delete first matching document, optional parameters are: w, wtimeout, j
    db.machine.deleteMany( filter, <optional params> ) - delete all matching documents, optional parameters are: w, wtimeout, j
    db.machine.distinct( key, query, <optional params> ) - e.g. db.machine.distinct( 'x' ), optional parameters are: maxTimeMS
    db.machine.drop() drop the collection
    db.machine.dropIndex(index) - e.g. db.machine.dropIndex( "indexName" ) or db.machine.dropIndex( { "indexKey" : 1 } )
    db.machine.dropIndexes()
    db.machine.ensureIndex(keypattern[,options]) - DEPRECATED, use createIndex() instead
    db.machine.explain().help() - show explain help
    db.machine.reIndex()
    db.machine.find([query],[fields]) - query is an optional query filter. fields is optional set of fields to return.
                                                  e.g. db.machine.find( {x:77} , {name:1, x:1} )
    db.machine.find(...).count()
    db.machine.find(...).limit(n)
    db.machine.find(...).skip(n)
    db.machine.find(...).sort(...)
    ...
>

查看函数信息,直接输入函数名就可以了:

> db.machine.find
function (query, fields, limit, skip, batchSize, options) {
    var cursor = new DBQuery(this._mongo,
                             this._db,
                             this,
                             this._fullName,
                             this._massageObject(query),
                             fields,
                             limit,
                             skip,
                             batchSize,
                             options || this.getQueryOptions());

    {
        const session = this.getDB().getSession();

        const readPreference = session._serverSession.client.getReadPreference(session);
        if (readPreference !== null) {
            cursor.readPref(readPreference.mode, readPreference.tags);
        }

        const readConcern = session._serverSession.client.getReadConcern(session);
        if (readConcern !== null) {
            cursor.readConcern(readConcern.level);
        }
    }

    return cursor;
}
>

相关文章

  • MongoDB开发之 Shell其他特性

    运行 help MongoDB Shell 内置了帮助文档。 db.help()是数据库级别的帮助文档: db.{...

  • MongoDB开发之 shell

    JavaScript shell MongoDB的命令行工具是一个机遇JavaScript的数据库操作和管理工具。...

  • MongoDB Shell CRUD

    MongoDB Shell CRUD MongoDB 描述等存在参考官网及其他作者 系统环境: MongoDB 版...

  • MongoDB 4.0 事务实现解析

    MongoDB 4.0 引入的事务功能,支持多文档ACID特性,例如使用mongo shell进行事务操作 支持 ...

  • MongoDB开发之 Shell基本操作

    引子 运行 数据库 查看当前数据库: 选择数据库: 创建 执行插入操作: 查询 查询单条数据: 更新 执行查询操作...

  • shell

    Shell学习之Shell特性(一) - -零 - 博客园 https://www.cnblogs.com/-we...

  • MongoDB 执行 js 文件

    我们通常通过 MongoDB Shell 访问 MongoDB Server,在 shell 中执行指令以完成各...

  • MongoDB权限设置

    本文阅读对象: MongoDB权限设置不熟悉者 MongoDB开发者 其他对MongoDB感兴趣的开发者 对技术感...

  • Mongo Shell交互式命令窗口 --- 2022-04-0

    mongo shell是MongoDB的交互式命令窗口。可以使用mongo shell操作MongoDB,例如:对...

  • MongoDB 客户端命令

    进入MongoDB Shell 进入MongoDB的安装目录的bin目录下,执行./mongo进入MongoDB ...

网友评论

      本文标题:MongoDB开发之 Shell其他特性

      本文链接:https://www.haomeiwen.com/subject/jnymnktx.html