美文网首页
mongo相关操作

mongo相关操作

作者: IT界刘德华 | 来源:发表于2018-12-17 16:35 被阅读0次

    查看是否走索引

    db.find(query).explain();
    

    索引常用命令

    查看当前索引状态
     db.collection.getIndexes();
    
    创建普通的单列索引
    db.collection.ensureIndex({field:1/-1});  //1是升续 2是降续
    
    创建多列索引
    db.collection.ensureIndex({field1:1/-1, field2:1/-1});
    
    删除单个索引
    db.collection.dropIndex({filed:1/-1});
    
    删除所有索引
    db.collection.dropIndexes();
    
    创建唯一索引
    db.collection.ensureIndex({filed.subfield:1/-1}, {unique:true});
    
    嵌套查询
        {"devModel":"SC1200","fieldId":"201810101426402264","number":1,"seedFieldTypeId":"116","seedFieldTypeName":"配种舍",
        "sn":"866192031889460","timestamp":1544629680000,"type":"OUTDOOR_TEMPERATURE","value":-2.1,"warning":false}
        
        
        内层查询
        db.getCollection('data_manage').find({"sensorDataList.type":{"$in":["OUTDOOR_TEMPERATURE","NH3"]}})

    相关文章

      网友评论

          本文标题:mongo相关操作

          本文链接:https://www.haomeiwen.com/subject/vlcckqtx.html