mongodb - How to use DBObject Query in distinct function of mongo template? -
i want find distinct value of field query criteria. code is..
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; }
in mongo template distinct function defined
mongotemplate.getcollection(collection).distinct(key, query)
bu code giving error because using simple query object instead of dbobject query. how can use dbobject query here?
use basicdbobject this:
public list searchservice(string th_type) { basicdbobject dbobject = new basicdbobject(); dbobject.append("th_type", th_type); dbcollection dbcollection = operations.getcollection("doclist"); list list = dbcollection.distinct("th_type", dbobject); return list; }
update:
with regex:
basicdbobject regexquery = new basicdbobject(); regexquery.put("th_type", new basicdbobject("$regex", th_type)); list list = operations.getcollection("doclist").distinct("th_type",regexquery);
Comments
Post a Comment