db中有符合該條件的資料。
Query query=new Query(
Criteria.where("AAA").is(XXobj.getAAA()).
orOperator(Criteria.where("BBB").is(XXobj.getBBB()))
);
find()方法:
List<XXObject> result = mongoTemplate.find(query, XXObject.class);
if(result!=null && !result.isEmpty()){
return result.get(0);
}
findOne()方法:
XXObject obj = mongoTemplate.findOne(query, XXObject.class);
if(obj!=null){
return obj;
}
問:
為什麼同樣的條件,這兩個查詢的結果卻不一樣? (我遇到的問題是findOne查詢結果為空)。
附:
官方文件對findOne和find的說明:
findOne Map the results of an ad-hoc query on the collection to a single instance of an object of the specified type.
find Map the results of an ad-hoc query on the collection to a List of the specified type.
看起來沒什麼差別。
小伙看你根骨奇佳,潜力无限,来学PHP伐。