MongoDB - The mongo Shell, Access the mongo Shell Help

本文档介绍了 MongoDB Shell 的在线帮助系统的使用方法,包括如何获取命令行选项、数据库操作帮助、集合操作帮助及游标处理等。通过这些帮助信息,用户可以更好地掌握 MongoDB 的使用技巧。

In addition to the documentation in the MongoDB Manual, the mongo shell provides some additional information in its “online” help system. This document provides an overview of accessing this help information.

 

Command Line Help

To see the list of options and help for starting the mongo shell, use the --help option from the command line:

mongo --help

 

Shell Help

To see the list of help, in the mongo shell, type help:

help

 

Database Help

In the mongo shell:

  • To see the list of databases on the server, use the show dbs command:
    show dbs

    New in version 2.4: show databases is now an alias for show dbs

  • To see the list of help for methods you can use on the db object, call the db.help() method:
    db.help()
  • To see the implementation of a method in the shell, type the db.<method name> without the parenthesis (()), as in the following example which will return the implementation of the method db.updateUser():
    db.updateUser

 

Collection Help

In the mongo shell:

  • To see the list of collections in the current database, use the show collections command:
    show collections
  • To see the help for methods available on the collection objects (e.g. db.<collection>), use the db.<collection>.help() method:
    db.collection.help()

    <collection> can be the name of a collection that exists, although you may specify a collection that doesn’t exist.

  • To see the collection method implementation, type the db.<collection>.<method> name without the parenthesis (()), as in the following example which will return the implementation of the save()method:
    db.collection.save

 

Cursor Help

When you perform read operations with the find() method in the mongo shell, you can use various cursor methods to modify the find() behavior and various JavaScript methods to handle the cursor returned from the find() method.

  • To list the available modifier and cursor handling methods, use the db.collection.find().help() command:
    db.collection.find().help()

    <collection> can be the name of a collection that exists, although you may specify a collection that doesn’t exist.

  • To see the implementation of the cursor method, type the db.<collection>.find().<method> name without the parenthesis (()), as in the following example which will return the implementation of the toArray() method:
    db.collection.find().toArray

 Some useful methods for handling cursors are:

  • hasNext() which checks whether the cursor has more documents to return.
  • next() which returns the next document and advances the cursor position forward by one.
  • forEach(<function>) which iterates the whole cursor and applies the <function> to each document returned by the cursor. The <function> expects a single argument which corresponds to the document from each iteration.

For examples on iterating a cursor and retrieving the documents from the cursor, see cursor handling. See also Cursor for all available cursor methods.

 

Wrapper Object Help

To get a list of the wrapper classes available in the mongo shell, such as BinData(), type help misc in the mongo shell:

help misc

 

转载于:https://www.cnblogs.com/huey/p/6120288.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值