I'm trying to execute JavaScript equivalent query in Java using the $where clause. The JavaScript query looks like this:
var currDate = new ISODate()
db.getCollection('rides')
.find(
{
"startDate" : {
"$lte" : currDate
},
"stopDate" : {
"$gte" : currDate
},
$where : function() { return (this.weekday == new Date(new ISODate().getTime() + this.timeOffset).getDay()) }
}
)
While weekday and timeOffset are document fields. This query works just fine in MongoDB shell. I'm trying to find out a way to write this query in Java 8. I've tried the following:
BasicDBObject query = new BasicDBObject("stopDate",new BasicDBObject("$gte", currDate))
.append("startDate",new BasicDBObject("$lte", currDate))
.append("weekday",
new BasicDBObject("$where", () ->
{
return (this.weekday == currDate + this.timeOffset)
}));
However I can't even compile this code. Java this is not recognized. Is there a way to accomplish the query in Java?
Thanks in advance for help!