`
leonzhx
  • 浏览: 770531 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Advanced usage of MongoDB JavaScript shell

阅读更多

 

1.   If a line contains open '(' or '{' characters, the shell will request more input before evaluating. You can press Enter twice to terminate line entry.

 

2.   Key Shortcuts:

  a)   up/down array for command history

  b)   in v1.9+ some basic emacs keystrokes work

  c)   ctrl-l to clear the screen

  d)   tab for auto-complete (newer versions only)

  e)   ctrl-c to exit

  f)   Enter twice to break out of line continuation mode

 

3.   The shell's prompt can be customized by creating variable 'prompt' in the shell. It can be any arbitrary javascript, including a function that returns a string:

 

> cmdCount = 1;

> prompt = function() {

... return (cmdCount++) + "> ";

... }

1> command

2> anothercommand

3> 
 

 

4.   We've added a feature to allow you edit larger values including functions using your editor of choice. Just run edit nameOfVariableOrFunction and we will open whatever editor you have defined in your EDITOR environment variable. Make sure that you save the file when editing. If you wish to discard your changes, you can either not save or make your editor exit with an error (:cq in Vim or (kill-emacs 1) in Emacs).

 

5.  B y default, the shell treats all numbers as floating-point values. You have the option to work with 64 bit integers by using a class built into the shell called NumberLong() .

 

6.   The Date() function returns a string and a "new Date() " will return an object (which is what you should use to store values).

 

7.   The BSON BinData datatype is represented via class BinData in the shell. Run help misc for more information.

 

8.   The MongoDB shell is not just an interactive shell, it can also be scripted using JS files:

./mongo server:27017/dbname --quiet my_commands.js
 

 

This command will execute the my_commands.js as if it had been entered into the shell directly.

 

9.   --quiet is a flag for the mongo command. This switch removes some header information that is not typically necessary when building unattended scripts.

 

10.   In addition to using a full Javascript file you can also pass in a Javascript fragment:

./mongo test --eval "printjson(db.getCollectionNames())"

 

 

 

11.   use dbname does not work in scripted mode. Instead you will need to explicitly define the database in the connection. Alternately, you can also create a connection within the script. Or you can use:

> db = db.getSiblingDB("otherdb")
 

 

12. The iterator command it does not work outside of the interactive scripting environment.

 

13. When running an update/insert command from the shell, the shell automatically awaits a reply (i.e. runs a get last error ). The same is not true when running from a script file. To wait for the status of an operation (such as a write), run the getLastError function after update/insert.

分享到:
评论
1 楼 hill124 2013-05-13  
牛人啊,看了这么多书,文章都是English,好奇博主是怎样的人物

相关推荐

    MongoDB(mongodb-shell-linux-x86_64-rhel70-5.0.4.tgz)

    MongoDB Community Server(mongodb-shell-linux-x86_64-rhel70-5.0.4.tgz)适用于RedHat / CentOS 7.0 MongoDB是一个基于分布式文件存储的数据库。由C++语言编写。旨在为WEB应用提供可扩展的高性能数据存储解决方案...

    sysbench-mongo:MongoDB javascript shell 的 sysbench 克隆

    sysbench mongo MongoDB javascript shell 的 sysbench 克隆

    dump-mongodb.sh(备份MongoDB数据库shell)

    Mongodb备份数据库的shell脚本文件, 经过在实际项目中测试使用过.

    MongoDB(mongodb-shell-linux-x86_64-suse12-5.0.4.tgz)

    MongoDB Community Server(mongodb-shell-linux-x86_64-suse12-5.0.4.tgz)适用于SUSE12 MongoDB是一个基于分布式文件存储的数据库。由C++语言编写。旨在为WEB应用提供可扩展的高性能数据存储解决方案。 MongoDB是...

    MongoDB(mongodb-shell-linux-x86_64-suse15-5.0.4.tgz)

    MongoDB Community Server(mongodb-shell-linux-x86_64-suse15-5.0.4.tgz)适用于SUSE15 MongoDB是一个基于分布式文件存储的数据库。由C++语言编写。旨在为WEB应用提供可扩展的高性能数据存储解决方案。 MongoDB是...

    MongoDB(mongodb-shell-linux-x86_64-debian10-5.0.4.tgz)

    MongoDB Community Server(mongodb-shell-linux-x86_64-debian10-5.0.4.tgz)适用于Debian10 MongoDB是一个基于分布式文件存储的数据库。由C++语言编写。旨在为WEB应用提供可扩展的高性能数据存储解决方案。 ...

    docker-mongodb-shell:在Docker容器中安装mongo shell和工具的示例

    mongodb-org-shell ,包含mongo shell。 mongodb-org-tools ,包含以下MongoDB工具:mongoimport bsondump,mongodump,mongoexport,mongofiles,mongorestore,mongostat和mongotop。 docker build --rm -t ...

    PyPI 官网下载 | mongodbshell-0.1a4.tar.gz

    资源来自pypi官网。 资源全名:mongodbshell-0.1a4.tar.gz

    mongodb shell指令

    mongodb shell指令,在后台shell进行数据操作!

    MongoDB的JavaScript驱动Narwhal.zip

    // Now, lets add lots of little documents to the collection so we can explore queries and cursors for (var i=0; i ; i ) { coll.insert({"i": i}); } print(coll.getCount()); // Let's get all the ...

    MongoDB(mongodb-org-shell-5.0.4-1.suse12.x86_64.rpm)

    MongoDB Community Server(mongodb-org-shell-5.0.4-1.suse12.x86_64.rpm)适用于SUSE12 MongoDB是一个基于分布式文件存储的数据库。由C++语言编写。旨在为WEB应用提供可扩展的高性能数据存储解决方案。 MongoDB是...

    MongoDB 3 Succinctly

    Zoran Maksimovic’s MongoDB 3 Succinctly touches on the most important aspects of the MongoDB database that application developers should be aware of—from installation and the usage of the Mongo ...

    MongoDB(mongodb-org-shell_5.0.4_amd64.deb)

    MongoDB Community Server(mongodb-org-shell_5.0.4_amd64.deb)适用于适用于Debian10 MongoDB是一个基于分布式文件存储的数据库。由C++语言编写。旨在为WEB应用提供可扩展的高性能数据存储解决方案。 MongoDB是一...

    MongoDB(mongodb-org-shell-5.0.4-1.el7.x86_64.rpm)

    MongoDB Community Server(mongodb-org-shell-5.0.4-1.el7.x86_64.rpm)适用于RedHat / CentOS 7.0 MongoDB是一个基于分布式文件存储的数据库。由C++语言编写。旨在为WEB应用提供可扩展的高性能数据存储解决方案。 ...

    MongoDB Shell命令.pdf

    大作业速看 mongodb shell 最全命令

    MongoDB(mongodb-org-shell-5.0.4-1.suse15.x86_64.rpm)

    MongoDB Community Server(mongodb-org-shell-5.0.4-1.suse15.x86_64.rpm)适用于SUSE15 MongoDB是一个基于分布式文件存储的数据库。由C++语言编写。旨在为WEB应用提供可扩展的高性能数据存储解决方案。 MongoDB是...

    shell实现自动备份mongodb

    实现mongodb自定义备份,可实现自定义库、自定义集合、自定义备份周期,使用方便,脚本易维护!

    Mastering MongoDB 3.x

    The book is based on MongoDB 3.x and covers topics ranging from database querying using the shell, built in drivers, and popular ODM mappers to more advanced topics such as sharding, high ...

    MONGOdb视频教程地址.txt

    shell详.mp4 1.4、-MongoDB文档、集合、数据库的概念.mp4 1.5、-MongoDB数据类型.mp4 123.txt 2.1、_MongoDB增、删、改文档】.mp4 2.2、-MongoDB查询语法1.mp4 2.3、_MongoDB查询语法2.mp4 2.4、-MongoDB查询...

    mongodb 数据库基本操作.docx

    通常,你可以使用 MongoDB 的 shell 或一个 MongoDB 客户端库(如 MongoDB Node.js 驱动程序)来连接到 MongoDB 服务器。 使用 MongoDB shell 的示例: bash mongo --host localhost --port 27017 2. 显示所有...

Global site tag (gtag.js) - Google Analytics