js倒計時兩種實現放大
find 查詢
簡單查詢
db.getCollection('spliteBuildingOfDay').find({nodeName:'南塔8F',itemCode: '03'})
相當於SQL語句中的 select * fromspliteBuildingOfDay wherenodeName='南塔8F' anditemCode = '03'
Java 查詢程式碼
Map<String, Object> matchMap = new HashMap<>();
matchMap.put("nodeName","南塔8F");
matchMap.put("itemCode","03");
like查詢
db.getCollection('spliteBuildingOfDay').find({nodeName:/南塔8F/,itemCode: '03'})
相當於SQL語句中的 select * fromspliteBuildingOfDay wherenodeName like '%南塔8F%' anditemCode = '03'
Java 查詢程式碼
Map<String, Object> matchMap = new HashMap<>();
matchMap.put("itemCode","03");
BasicDBList values = new BasicDBList();
Pattern pattern = Pattern.compile("^.*" + "南塔8F" + ".*$", Pattern.CASE_INSENSITIVE);
values.add(new BasicDBObject("nodeName", pattern));
matchMap.put("nodeName",pattern);
in查詢
db.getCollection('spliteBuildingOfDay').find({nodeName:南塔8F,itemCode: {$in:['01','02']}})
相當於SQL語句中的 select * fromspliteBuildingOfDay wherenodeName like '%南塔8F%' anditemCode in('01','02')
Java 查詢程式碼
Map<String, Object> matchMap = new HashMap<>();
matchMap.put("nodeName","南塔8F");
List<String> idList = new ArrayList<String>();
idList.add("01");
idList.add("02");
matchMap.put("itemCode", new BasicDBObject("$in", idList));
db.getCollection('spliteBuildingOfDay').find({ $or:[{nodeName:'北塔8F'},{nodeName:'南塔8F'} ]})
相當於SQL語句中的 select * fromspliteBuildingOfDay wherenodeName ='北塔8F' or nodeName = '南塔8F'
Java 查詢程式碼
Map<String, Object> matchMap = new HashMap<>();
BasicDBList orList = new BasicDBList();
orList.add("北塔8F");
orList.add("南塔8F");
matchMap.put("$or",orList);
db.getCollection('spliteBuildingOfDay').find({ $or:[{nodeName:/北塔8F/},{nodeName:/南塔8F/} ]})
相當於SQL語句中的 select * fromspliteBuildingOfDay wherenodeName like '%北塔8F%' or nodeName = '%南塔8F%'
Map<String, Object> matchMap = new HashMap<>();
BasicDBList orList = new BasicDBList();
Pattern pattern = Pattern.compile("^.*" + "南塔" + ".*$", Pattern.CASE_INSENSITIVE);
values.add(new BasicDBObject("nodeName", pattern));
Pattern pattern = Pattern.compile("^.*" + "北塔" + ".*$", Pattern.CASE_INSENSITIVE);
values.add(new BasicDBObject("nodeName", pattern));
matchMap.put("$or",values);
aggregate統計
可用於 分組 統計 複雜查詢
Java中進行封裝 查詢
Map<String, Object> matchMap = new HashMap<>();