Spring + MongoDB 利用MongoTemplate查詢的問題
伊谢尔伦
伊谢尔伦 2017-04-24 09:13:09
0
0
602

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

全部回覆(0)
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板