【mongo】基础操作

  • 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 &quot; : &quot; 100 &quot; , &quot; gte&quot;:&quot;100&quot;,&quot; 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()
  • 数据导出

    • 导出成 csv

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

吴姬压酒

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值