Spring + MongoDB 利用MongoTemplate查询的问题
伊谢尔伦
伊谢尔伦 2017-04-24 09:13:09
0
0
510

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伐。

reply all (0)
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!