[JAVA-1852] how apply pagination and sorting functionality issue collection.distinct() Created: 02/Jun/15  Updated: 11/Sep/19  Resolved: 23/Jun/15

Status: Closed
Project: Java Driver
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: basker Assignee: Unassigned
Resolution: Done Votes: 0
Labels: query
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

unix- eclipse- java



 Description   

sample code:
String where="

{'photo_id':"+photoId+",'flag':true,'type':\""+type+"\"}

";
DBObject whereCond = (DBObject) JSON.parse(where);
DBCollection collection = mongoTemplate.getCollection("photo_user_action_log");
List<Integer> userList=collection.distinct("user_id", whereCond);
=========================================================
like this i want :
//cursor.skip(startIndex);
//cursor.limit(recordPerPage);
//cursor.sort(new BasicDBObject("created.date", 1));



 Comments   
Comment by Jeffrey Yemin [ 08/Jun/15 ]

The server's distinct command doesn't support skip, limit, or sort. Have you looked at the aggregation framework as an alternative?

In the shell, it would look something like this:

> db.test.aggregate([{$match : {x : {$gt : 1 } } }, {$group : { _id : "$x" } }, {$sort : {_id : 1} }, {$skip : 1}, {$limit : 3}])
{ "_id" : 6 }
{ "_id" : 7 }
{ "_id" : 8 }

In the future, questions like this are better asked on either the mongodb-users Google group or Stack Overflow.

Regards,
Jeff

Generated at Thu Feb 08 08:55:40 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.