MongoDB Shell 学习(二)

本节主要讲述怎么去学习好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);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值