I am using java async driver for mongoDb not the default driver
I have a db 'test' with collection 'collect' with each document in the form given below where time is the 10 digit unix timestamp
{ "_id", "userId", "programId", "time" }
I wanted to write a query which is equivalent to the sql query given below where input1 is the current time in unix timestamp format and input2 is a userId as an input
SELECT *
FROM collect
WHERE time >= input1 AND userId = input2
ORDER BY time DESC
LIMIT 30
I did something like this
collection = db.getCollection("ProgramBookings"); Long Datetimesatmp =
new Date().getTime() / 1000;
Aggregate.Builder builder = new Aggregate.Builder();
builder = (builder.match(where("time").
greaterThan(Datetimesatmp.toString()).and("userId") .equals(userId.toString())).sort(desc("time"))).limit(30);
Aggregate d1 = builder.build();
here I meant only to retrieve list 'time' which follows the criteria. But I am stuck here couldn't find much helpful links after googling. I referred this link to do the above given code. Is there a simple way to do the same.
EDIT: And I want to add the values to a List of ProgramTime objects which is like
public class ProgramTime {
private Integer userId;
private Integer programId;
private Long time;
}