查看是否走索引
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"]}})