征服 Mongodb 之 常用命令、基本数据类型
手里有本《MongoDB权威指南》,打算做个读书笔记,把常规命令、数据类型过一遍,强迫记忆。
相关文章:
征服 Mongodb 之 安装与主从配置
关于如何安装、配置、启动MongoDB等,参考上篇文章。
一、常规命令
- 登录
类似于MySQL登录,可参考如下命令:
- # mongo --help
- MongoDB shell version: 2.0.7
- usage: mongo [options] [db address] [file names (ending in .js)]
- db address can be:
- foo foo database on local machine
- 192.169.0.5/foo foo database on 192.168.0.5 machine
- 192.169.0.5:9999/foo foo database on 192.168.0.5 machine on port 9999
- options:
- --shell run the shell after executing files
- --nodb don't connect to mongod on startup - no 'db address' arg expected
- --norc will not run the ".mongorc.js" file on start up
- --quiet be less chatty
- --port arg port to connect to
- --host arg server to connect to
- --eval arg evaluate javascript
- -u [ --username ] arg username for authentication
- -p [ --password ] arg password for authentication
- -h [ --help ] show this usage information
- --version show version information
- --verbose increase verbosity
- --ipv6 enable IPv6 support (disabled by default)
- file names: a list of files to run. files have to end in .js and will exit after unless --shell is specified
譬如,我经常这么用,一步到位:
- # mongo 10.11.20.140/zlex
- MongoDB shell version: 2.0.7
- connecting to: 10.11.20.140/zlex
- >