本节主要讲述怎么去学习好shell
1.利用shell自带的帮助命令
> help
db.help() help on db methods
db.mycoll.help() help on collection methods
rs.help() help on replica set methods
help connect connecting to a db help
help admin administrative help
help misc misc things to know
help mr mapreduce help
show dbs show database names
show collections show collections in current database
show users show users in current database
show profile show most recent system.profile entries wit
h time >= 1ms
use <db_name> set current database
db.foo.find() list objects in collection foo
db.foo.find( { a : 1 } ) list objects in foo where a == 1
it result of the last line evaluated; use to f
urther iterate
DBQuery.shellBatchSize = x set default number of items to display on s
hell
exit quit the mongo shell
2.使用db.help()查看数据库级别命令的帮助
> db.help();
DB methods:
db.addUser(username, password[, readOnly=false])
db.auth(username, password)
db.cloneDatabase(fromhost)
db.commandHelp(name) returns the help for the command
db.copyDatabase(fromdb, todb, fromhost)
db.createCollection(name, { size : ..., capped : ..., max : ... } )
db.currentOp() displays the current operation in the db
db.dropDatabase()
db.eval(func, args) run code server-side
db.getCollection(cname) same as db['cname'] or db.cname
db.getCollectionNames()
db.getLastError() - just returns the err msg string
db.getLastErrorObj() - return full status object
db.getMongo() get the server connection object
db.getMongo().setSlaveOk() allow this connection to read from the nonma
ter member of a replica pair
db.getName()
db.getPrevError()
db.getProfilingLevel() - deprecated
db.getProfilingStatus() - returns if profiling is on and slow threshold
2.使用db.foo.help()查看集合相关帮助
> db.blog.help()
DBCollection help
db.blog.find().help() - show DBCursor help
db.blog.count()
db.blog.dataSize()
db.blog.distinct( key ) - eg. db.blog.distinct( 'x' )
db.blog.drop() drop the collection
db.blog.dropIndex(name)
db.blog.dropIndexes()
db.blog.ensureIndex(keypattern[,options]) - options is an object with th
ese possible fields: name, unique, dropDups
db.blog.reIndex()
db.blog.find([query],[fields]) - query is an optional query filter. fiel
ds is optional set of fields to return.
e.g. db.blog.find( {x:77}
, {name:1, x:1} )
db.blog.find(...).count()
db.blog.find(...).limit(n)
db.blog.find(...).skip(n)
db.blog.find(...).sort(...)
db.blog.findOne([query])
db.blog.findAndModify( { update : ... , remove : bool [, query: {}, sort
: {}, 'new': false] } )
db.blog.getDB() get DB object associated with collection
4.查看函数的JavaScript源码
> db.blog.find
function (query, fields, limit, skip) {
return new DBQuery(this._mongo, this._db, this, this._fullName, this._massag
eObject(query), fields, limit, skip);
}
分享到:
相关推荐
MongoDB是一个开源的NoSQL数据库,以高性能、高可用性和易于扩展性而著名。它使用了一种灵活的、基于文档的数据模型,被称为BSON...总的来说,MongoDB Shell命令的学习和使用是掌握MongoDB数据库管理不可或缺的一部分。
MongoDB Shell 下载 版本:2.3.3 Windows x64
10. **MongoDB工具**:MongoDB提供了一系列工具,如`mongo` shell(交互式命令行)、`mongodump`和`mongorestore`(用于备份和恢复)、`mongostat`和`mongotop`(监控数据库性能)等。 学习MongoDB的过程中,建议先...
10. **MongoDB工具**:MongoDB提供了一系列的管理工具,如`mongo shell`、`mongodump/mongorestore`、`mongostat/mongotop`等,了解它们的用途和使用方法可以帮助更有效地管理和维护数据库。 11. **MongoDB驱动程序...
在学习MongoDB时,建议阅读官方文档以及相关的权威指南,如提到的参考文献,以便深入理解和掌握MongoDB的全面功能。同时,实践是提升技能的关键,通过实际操作MongoDB Shell,可以更好地理解其工作原理和使用技巧。
### MongoDB学习手册精要知识点概览 #### 一、MongoDB简介 MongoDB,源于英文单词“humongous”,意指其设计初衷在于处理海量数据。作为一款开源、面向文档的NoSQL数据库,MongoDB凭借其灵活性和高性能,迅速成为...
- 使用`nohup`命令后台启动MongoDB服务,通过`./mongodb-xxxxxxx/bin/mongo`进入交互式shell进行数据库操作。 #### PHP操作MongoDB实战指南 - **连接MongoDB**:在PHP中使用MongoDB前,需确保已安装并启用`...
### MongoDB 学习笔记知识点详解 #### 一、MongoDB 命令行基础操作 **1.1 帮助命令** - **help**:显示 MongoDB shell 的基本帮助信息。 - **db.help()**:提供当前数据库的帮助信息。 - **db.mycoll.help()**:...
#### 二、MongoDB安装与配置 ##### 1. Linux环境下的安装 - 使用PECL安装MongoDB驱动: ```shell # sudo pecl install mongo ``` - 配置`php.ini`文件启用扩展: ```shell # vi /etc/php.ini extension=mongo....
MongoDB Shell是MongoDB数据库系统的一个重要...通过不断学习和实践,你可以熟练掌握MongoDB Shell,从而更好地利用MongoDB数据库。记得参考官方文档(https://mongodb.net.cn/manual/mongo/)获取最新和最详尽的信息。
登录MongoDB shell使用`mongo`命令,可以连接本地或远程服务器,若要连接非默认端口,需指定IP和端口号。 MongoDB的基本操作包括: - **选择或创建数据库**:使用`use`命令切换或创建数据库。 - **插入文档**:...
在本压缩包文件中,包含的是MongoDB针对Windows 32位系统的2.4.6版本安装包,这是一个较早的版本,但对于学习和理解MongoDB的基本操作和原理仍然具有参考价值。 MongoDB的安装步骤如下: 1. **下载与解压**:首先...
"MongoDB架构简析"部分,我们需要理解MongoDB的三个主要组件:Mongod、MongoDB Shell和MongoDB复制集。Mongod是数据库服务器,负责处理数据的存储和检索;MongoDB Shell是一个交互式JavaScript环境,用于管理数据库...
4. **MongoDB工具**:包括`mongod`(数据库服务)、`mongo`(交互式Shell)、`mongoimport/export`(数据导入导出)、`mongorestore/dump`(数据备份与恢复)以及`mongooplog`(操作日志回放)和`mongostat`(服务器...
MongoDB Shell是MongoDB自带的命令行工具,它是学习和理解MongoDB语法的基础。在3.0版本后,MongoDB Shell增加了对新的数据库操作的支持,比如批量插入、聚合操作、新版本的索引类型等。此外,它还提供了更丰富的...
MongoDB 是一种流行的开源、高性能、无模式的文档型数据库,设计用于处理和存储大量数据。...通过其直观的命令行接口和强大的查询语言,MongoDB 提供了一个易于学习和使用的环境,使得开发者可以轻松地管理和操作数据。
#### 二、MongoDB安装与配置 - **Linux环境安装** 1. **下载安装包**:访问官方提供的下载页面(http://www.mongodb.org/downloads),根据操作系统选择合适的版本。 2. **解压安装包**: ```bash tar -zxvf ...
### MongoDB学习文档与Java集成详解 #### 一、MongoDB简介与安装 **MongoDB**是一种基于分布式文件存储的开源数据库系统,具有高性能、高可用性以及易扩展性等特点,适用于处理大规模数据集的应用场景。 ##### ...