zoukankan      html  css  js  c++  java
  • Mongodb 的常用方法,在可视化工具执行

    查询:

    db.getCollection('message').find({"userId":"31257"})
    

     查询总数:

    db.getCollection('message').find({"sendTimeStamp":{$gt:1517982993}}).count()
    

     条件删除数据:

    db.getCollection('message').remove({'title':'MongoDB 教程'})
    

     循环插入数据:

    for(var i=1;i<10;i++) db.getCollection('message').insert({"userId":"19290","pointsDelta" : 0})
    

     插入一条记录:

    db.getCollection('message').insert({"userId":"19290","pointsDelta" : 0})
    

     当前数据库状态:

    db.getCollection('message').stats()
    

     查看内存使用大小

    show dbs
    

     profiling功能

    db.getProfilingLevel(1)
    

     0 代表不开启

    1 代表记录慢指令(默认100ms)

    2 代表记录所有指令

    db.setProfilingLevel(1)
    

     删除查询的数据

    show dbs
    use cpeducloud
    
    //db.getCollection('historylog').count();
    
    var mydata = db.getCollection('historylog').find({},{'_id':1}).sort({'_id':1}).limit(10);
    while(mydata.hasNext()){
        var one = mydata.next();
        printjson(one);
        db.getCollection('historylog').remove(one);
     }
    
      //db.getCollection('historylog').remove({'_id':ObjectId("5d2304aab8b5ea5745d0b415")});

    根据时间查询

     db.getCollection('applog').remove({"startTime":{$lte:ISODate("2019-11-15 02:18:56.248Z")}});
    

    更改此值,使其生效。

  • 相关阅读:
    利用ssh的私钥登录Linux server
    PSR-2 代码风格规范
    MySQL的四种事务隔离级别
    table添加横向滚动条
    转换图片大小
    百度地图Label 样式:label.setStyle
    鼠标的几种常用样式
    百度地图API-自定义图标覆盖物
    微信公众号自定义菜单中可加入的表情
    微信公众号项目总结
  • 原文地址:https://www.cnblogs.com/sunxun/p/9646279.html
Copyright © 2011-2022 走看看