-
windows
- mongod – dbpath=D:\mongoDB\db --port 8822
-
mongo shell
- 登入
- ./mongo --port 8822
- 登入
-
整库导入
- mongrestore -h localhost:8800 -d operation <文件目录>
-
mongo shell api (pymongo与之相差无几)
-
指定返回字段
- 在find的第二个参数中指定
- db.collections.find({},{“field”:1})
-
区间查找
- db.collections.find({“actual”:{“ g t e " : " 100 " , " gte":"100"," gte":"100","lte”:“200”}})
-
skip and limit
-
skip
- 跳过多少条
-
-
-
mongo改字段名
- db.post.update({$rename:{url:‘site’}});
-
CRUD
-
update
- 只更新第一条记录:
db.col.update( { “count” : { $gt : 1 } } , { $set : { “test2” : “OK”} } );
全部更新:
db.col.update( { “count” : { $gt : 3 } } , { $set : { “test2” : “OK”} },false,true );
只添加第一条:
db.col.update( { “count” : { $gt : 4 } } , { $set : { “test5” : “OK”} },true,false );
全部添加加进去:
db.col.update( { “count” : { $gt : 5 } } , { $set : { “test5” : “OK”} },true,true );
全部更新:
db.col.update( { “count” : { $gt : 15 } } , { $inc : { “count” : 1} },false,true );
只更新第一条记录:
db.col.update( { “count” : { $gt : 10 } } , { $inc : { “count” : 1} },false,false );
- 只更新第一条记录:
-
-
查询集合索引
- db.overall_information.getIndexes()
-
查询大小
- db.stats()
-
查看连接数
- db.serverStatus().connections
-
查看慢命令
-
创建慢命令库
- db.createCollection( “system.profile”, { capped: true, size:4000000 } )
-
查看慢命令记录
- db.system.proflile.find()
-
-
查看某命令的扫描情况
- db.mid_large_width_table.find({}).explain()
-
启动路由进程
-
/usr/local/mongoDB/bin/mongos --port 40000 --configdb localhost:27100 --fork –
-
logpath=/www/mongoDB/shard/log/route.log --chunkSize 500
-
-
连接到mongos路由进程
- /usr/local/mongoDB/bin/mongo --port 27000
-
查看分片情况
- use config
- db.shards.find()
-
数据导出
【mongo】基础操作
最新推荐文章于 2022-11-23 18:50:50 发布