My document has attribute 'timestamp' and I want to get all older than n days. The following query works just fine in mongodb shell:
{timestamp: { $gt: Date.now() - 1000*60*60*24*?0 } }
But when putting it inside Query anotation like this:
public interface TestRepo extends MongoRepository<TestEntry, String> {
@Query("{timestamp: { $gt: Date.now() - 1000*60*60*24*?0 } }")
Stream<TestEntry> get(Integer days);
}
I get json parse exception
Caused by: com.mongodb.util.JSONParseException:
{timestamp: { $gt: Date.now() - 1000*60*60*24?0 } }
^
at com.mongodb.util.JSONParser.parse(JSON.java:231) ~[mongo-java-driver-3.8.2.jar:na]
...
JSONand you have aJavaScriptcall inside. You have to use parameter and bind your's call value to it.