1
我想用某些查詢條件查找不同的字段值。我的代碼是..如何在mongo模板的不同功能中使用DBObject查詢?
public List searchservice(String th_type) {
Query query = new Query();
query.addCriteria(Criteria.where("th_type").regex(th_type));
List list = operations.getCollection("doclist").distinct("th_type", query);
return list;
}
在蒙戈模板一個獨特的功能定義
mongoTemplate.getCollection(collection).distinct(key, query)
BU我的代碼,因爲我使用的,而不是DBOBJECT查詢簡單的查詢對象給錯誤。我如何在這裏使用DBObject查詢?
我想使用正則表達式(th_type)..will它的工作。 – 2015-04-01 09:51:33
完成.. \t \t BasicDBObject regexQuery = new BasicDBObject();新的BasicDBObject(「$ regex」,th_type));};}};}}} \t \t \t \t List list = operations.getCollection(「doclist」)。distinct(「th_type」,regexQuery); – 2015-04-01 10:03:00
@DeepakPareek太棒了,我已經更新了我的答案以反映您的更改。 – chridam 2015-04-01 10:11:47