1、查询所有
db.modelMapModelElement.find({})
.projection({})
.sort({_id:-1})
.limit(100)
2、删除数据
db.modelMapComponentElement.drop();
db.modelMapComponentFloor.drop();
db.modelMapModelElement.drop();
db.modelMapComponent.drop();
3、查询某个值
db.modelMapComponentElement.find({"elementName":"其他块料墙面"})
.projection({})
.sort({_id:-1})
.limit(100)
db.modelMapComponentElement.find({
"mapId":"d2d4ac92-c394-48a0-ac60-002f8870a584",
componentList:{$elemMatch: {componentId:"3rKNFlJhr40Qi1YkZK1nzp"}}
}).forEach(function(item){
for(var i=0;i<item.componentList.length;i++){
if(item.componentList[i].componentId == "3rKNFlJhr40Qi1YkZK1nzp"){
print(i)
print(item.componentList[i])
}
}
})
4、模糊查询
db.modelMapComponentFloor.find({"_id":/b46b83c8-5a5c-4b90-bfc1-8c8513cae281/})
.projection({})
.sort({_id:-1})
.limit(100)
5、删除
db.modelMapComponent.remove({"_id":/5a952941-02c3-4023-9085-2f95c7d065a4/});
6、查询大小
db.modelMapComponent.find({
"mapId":"20c5e925-20f9-4032-85c9-d387dfb8f44e",
//"componentId":"15BIZ49vHDKf6PBoWe2c81"
}).count()
var total=0;
db.modelMapComponentElement.find({
"mapId":"20c5e925-20f9-4032-85c9-d387dfb8f44e",
}).forEach(function(item){
total+=item.componentList.length;
})
print(total)
var total=0;
db.modelMapComponentHouse.find({
"mapId":"178558932749434880",
}).forEach(function(item){
var roomList = item.roomList;
roomList.forEach(function(room){
var modelList = room.modelList;
modelList.forEach(function(model){
total+=model.componentList.length;
});
});
});
print(total);
6、更新脚本
db.modelMapComponent.update({"mapId":"e8a4be9c-1e8c-49d6-98a7-0cf326d97549"},{$set:{"houseName":"其他分区","roomName":"其他空间"}},false,true);
db.modelMapComponentHouse.update({"mapId":"e8a4be9c-1e8c-49d6-98a7-0cf326d97549"},
{$set:{
"houseName":"其他分区",
"roomList.$[].roomName":"其他空间"
}},
false,true);
/**
* 根据idList查找自定义属性数据
*
* @param idList
* @return
*/
@Override
public List<ModelComponentProperties> listCustomPropertiesByIdList(List<String> idList) {
Query query = new Query();
query.addCriteria(Criteria.where("_id").in(idList));
//不查询固有属性数据
query.fields().exclude("fixedPropertySets");
return mongoTemplate.find(query, ModelComponentProperties.class);
}
/**
* 根据idList查找所有数据
*
* @param idList
* @return
*/
@Override
public List<ModelComponentProperties> selectListByIdList(List<String> idList) {
Query query = new Query();
query.addCriteria(Criteria.where("_id").in(idList));
return mongoTemplate.find(query, ModelComponentProperties.class);
}
7、建索引
db.modelMapComponentFloor.createIndex({mainDataBuildingFloorId: -1});
db.modelMapComponentFloor.createIndex({mapId: -1});
db.modelMapComponentFloor.createIndex({mapId: -1, mainDataBuildingFloorId: -1})