zoukankan      html  css  js  c++  java
  • MongoDB小技巧总结

    1 mongodb索引操作

    2 mongodb内嵌查询

    嵌套对象查询

    {"report_content.measurement_judgment.enabled":true}
    

      

    3 mongodb更新操作

    parame1:查询条件

    param2:局部更新字段

    param3:false代表不存在时是否要新增记录

    param4:是否批量更新,为false时只更新检索到的第一条数据

    db.collection.update({"field":"value"},{$set:{'field':'value'}},false,true);
    

    4 mongdb更新操作:将B字段赋值给A字段

    db.eval(function() { 
        db.collection.find().forEach(function(e) {
            e.phyHealthReuslt = e.phyModelReuslt;
            e.phyHealthPoint = e.phyModelPoint;
            db.collection.save(e);
        });
    });
    

     

    5 修改字段的数据类型

    NumberLong类型转换为string类型  

    db.sleepReportV2.find({"reportId":{$type:18}}).forEach(
        function(x){
            x.reportId =  x.reportId + "";
            // 这行代码不行,将Long字段207转换成字符串NunberLong(207)
            //x.reportId = String(x.reportId);
            db.sleepReportV2.save(x)
        });
    

      

    db.sleepReportV2.find({"reportId":{$type:18}}).count();
    

      

    业务需求变更永无休止,技术前进就永无止境!
  • 相关阅读:
    Oracle-创建PDB
    win10怎么看IP地址、怎么看主机名
    怎么读dll文件
    Windows的注册表是什么?
    DbHelperOra类的相关链接(没看)
    C#中//注释和///注释的区别
    有关C#的序列化
    【智能指针 | 01】std::shared_ptr的使用教程
    coreump
    d
  • 原文地址:https://www.cnblogs.com/yucongblog/p/15682277.html
Copyright © 2011-2022 走看看