6.mongo命令提示符帮助
发表于:2025-02-23 作者:千家信息网编辑
千家信息网最后更新 2025年02月23日,6.mongo命令提示符帮助最新内容会在源站更新.转载请保留原文链接: http://dashidan.com/article/mongodb/index.html① mongo命令行参数帮助通过--
千家信息网最后更新 2025年02月23日6.mongo命令提示符帮助
6.mongo命令提示符帮助
最新内容会在源站更新.转载请保留原文链接: http://dashidan.com/article/mongodb/index.html
① mongo命令行参数帮助
通过--help
参数显示命令行帮助信息
mongo --help
显示:
MongoDB shell version: 2.0.4usage: 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 9999options: --shell run the shell after executing files --nodb don't connect to mongod on startup - no 'db address' arg expected --norc 开始不执行".mongorc.js"文件 --quiet 安静模式 --port arg 端口 --host arg IP --eval arg 运行javascript脚本 -u [ --username ] arg 用户名 -p [ --password ] arg 密码 -h [ --help ] 显示这个帮助信息 --version 版本号 --verbose increase verbosity --ipv6 开启IPv6支持(默认关闭)
② mongo指令帮助
通过命令提示符连上mongo数据库后,可以输入help
来显示命令提示符帮助.
help
会显示:
db.help() 数据库方法帮助信息db.mycoll.help() 集合方法帮助信息rs.help() help on replica set methodshelp admin 管理员帮助信息help connect 连接数据库帮助help keys 快捷键help misc 杂项信息帮助help mr mapreduce帮助show dbs 显示全部数据库名show collections 显示当前数据库中的全部集合名show users 显示当前数据库的全部用户show profile show most recent system.profile entries with time >= 1msshow logs 显示可以连接的日志(`logger`)名show log [name] 输出内存中的最近log的片段, 默认输出`global`use设定当前数据库db.foo.find() 显示集合`foo`中的对象列表db.foo.find( { a : 1 } ) 查询foo集合中`a == 1`的对象it 输入it, 继续迭代显示结果, 输出更多结果DBQuery.shellBatchSize = x 设置显示结果条数exit 退出命令行
③ 数据库帮助
1.显示全部数据库
show dbs
2.显示部数据操作帮助
db.help()
3.显示方法的实现
显示一个数据的方法的具体实现,输入db.
不带()
. 例如:
db.updateUser
显示:
test.updateUser
④ 集合帮助
1.显示全部集合
show collections
2.显示集合帮助
db.collection.help()
显示
db.collection.find().help() - show DBCursor helpdb.collection.count()db.collection.dataSize()db.collection.distinct( key ) - eg. db.collection.distinct( 'x' )db.collection.drop() drop the collectiondb.collection.dropIndex(name)db.collection.dropIndexes()db.collection.ensureIndex(keypattern[,options]) - options is an object with these possible fields: name, unique, dropDupsdb.collection.reIndex()db.collection.find([query],[fields]) - query is an optional query filter. fields is optional set of fields to return. e.g. db.collection.find( {x:77} , {name:1, x:1} )db.collection.find(...).count()db.collection.find(...).limit(n)db.collection.find(...).skip(n)db.collection.find(...).sort(...)db.collection.findOne([query])db.collection.findAndModify( { update : ... , remove : bool [, query: {}, sort: {}, 'new': false] } )db.collection.getDB() get DB object associated with collectiondb.collection.getIndexes()db.collection.group( { key : ..., initial: ..., reduce : ...[, cond: ...] } )db.collection.mapReduce( mapFunction , reduceFunction ,)db.collection.remove(query)db.collection.renameCollection( newName , ) renames the collection.db.collection.runCommand( name , ) runs a db command with the given name where the first param is the collection namedb.collection.save(obj)db.collection.stats()db.collection.storageSize() - includes free space allocated to this collectiondb.collection.totalIndexSize() - size in bytes of all the indexesdb.collection.totalSize() - storage allocated for all data and indexesdb.collection.update(query, object[, upsert_bool, multi_bool])db.collection.validate( ) - SLOWdb.collection.getShardVersion() - only for use with shardingdb.collection.getShardDistribution() - prints statistics about data distribution in the cluster
3.显示集合方法实现
显示方法实现输入db.
, 不带()
. 例如输入:
db.collection.save
显示:
function (obj) { if (obj == null || typeof obj == "undefined") { throw "can't save a null"; } if (typeof obj == "number" || typeof obj == "string") { throw "can't save a number or string"; } if (typeof obj._id == "undefined") { obj._id = new ObjectId; return this.insert(obj); } else { return this.update({_id:obj._id}, obj, true); }}
⑤ cursor帮助
当你在mongo命令行使用find()
方法时, 可以使用很多cursor
方法来修改find()
行为和结果.
显示find()方法可用的修改器和
cursor
处理方法db.collection.find().help()
显示:
> db.collection.find().help()find() modifiers .sort( {...} ) .limit( n ) .skip( n ) .count() - total # of objects matching query, ignores skip,limit .size() - total # of objects cursor would return, honors skip,limit .explain([verbose]) .hint(...) .showDiskLoc() - adds a $diskLoc field to each returned objectCursor methods .forEach( func ) .map( func ) .hasNext() .next()
看
cursor
方法的实现, 输入db.
, 不包含.find(). ()
. 例如:
db.collection.find().toArray
显示:
> db.collection.find().toArrayfunction () { if (this._arr) { return this._arr; } var a = []; while (this.hasNext()) { a.push(this.next()); } this._arr = a; return a;}
常用的cursor
方法
hasNext() 查询
cursor
是否还有数据.next() 返回下一个数据对象, 并且
cursor
指向位置加1.forEach(
) 方法遍历执行全部结果. 只有1参数, 迭代器中指向的对象.
⑥ 包装对象帮助
可以通过输入help misc
来获取对象包装类.
help misc
显示:
> help misc b = new BinData(subtype,base64str) create a BSON BinData value b.subtype() the BinData subtype (0..255) b.length() length of the BinData data in bytes b.hex() the data as a hex encoded string b.base64() the data as a base64 encoded string b.toString() b = HexData(subtype,hexstr) create a BSON BinData value from a hex string b = UUID(hexstr) create a BSON BinData value of UUID subtype b = MD5(hexstr) create a BSON BinData value of MD5 subtype o = new ObjectId() create a new ObjectId o.getTimestamp() return timestamp derived from first 32 bits of the OID o.isObjectId() o.toString() o.equals(otherid)
⑦ 参考文章
官方文档
帮助
数据
方法
数据库
命令
输入
信息
对象
结果
提示符
提示
参数
输出
指向
用户
包装
查询
迭代
安静
位置
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
软件开发费和软件许可
露脸视频软件开发
网络安全宣传周2020九中
如何同时筛选多行数据库
社会科学 英文数据库
配置与管理DNS服务器总结
服务器4期名录
华为服务器查管理地址
数据库习题作业
中科院网络安全视频讲解
天津时代网络技术服务
网络安全成果运用
香港服务器怎么设置右键
二维码解码网络安全
招商资源信息数据库
理正工程勘察数据库
芜湖erp软件开发费用多少
每台电脑都有服务器和ip吗
网络技术及应用是什么
网络安全个人反思
明日之后希望谷地服务器最强营地
数学不好 网络安全
公安局网络安全大队工作时间
sq数据库管理系统制作
神山服务器
黑莓q10服务器关了怎么激活
服务器如何添加安全狗
宁德市网络安全技术支持单位
软件开发论文1200字
合肥龙信网络技术有限公司