db中有符合该条件的数据。
Query query=new Query( Criteria.where("AAA").is(XXobj.getAAA()). orOperator(Criteria.where("BBB").is(XXobj.getBBB())) );
find()方法:
List 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的说明:
findOneMap the results of an ad-hoc query on the collection to a single instance of an object of the specified type.
findMap the results of an ad-hoc query on the collection to a List of the specified type.
看起来没什么区别啊。
小伙看你根骨奇佳,潜力无限,来学PHP伐。