Parse error on aggregation query.

148 views
Skip to first unread message

Rob Moore

unread,
May 12, 2016, 11:05:30 AM5/12/16
to Jongo
I've created an aggregation query which includes the following:

 .and(String.format("{ $match: { codingDates: { $gte: ISODate('%s') } } }", startDate)) // startDate is a Joda LocalDate

When I try to execute the query, I'm seeing the following:

java.lang.IllegalArgumentException: Cannot parse query: { $match: { codingDates: { $gte: ISODate('2010-08-06') } } }
 at org
.jongo.query.BsonQueryFactory.createQuery(BsonQueryFactory.java:162)
 at org
.jongo.Aggregate.and(Aggregate.java:50)

The query works in the MongoDB shell and I'm puzzled to why I'm seeing the exception. Any ideas?

Thanks,

Rob

P.S. I tried using the templating approach prior to using String.format but nothing is returned. I suspect that the query is issued with the hash value left unmodified in that case. 

Benoît GUEROUT

unread,
May 12, 2016, 3:23:56 PM5/12/16
to Jongo
Hello,

You should query with $date operator, it should look something like this "{ $match: { codingDates: { $gte: { '$date' : #} } } }"

Rob Moore

unread,
May 12, 2016, 5:46:37 PM5/12/16
to Jongo
Thanks, Benoît. I haven't used the $date operator before. 

Based on these docs, it looks like it's fair to say that Jongo supports strict mode rather than shell mode.

Benoît GUEROUT

unread,
May 13, 2016, 1:37:03 AM5/13/16
to Jongo
Indeed this is the strict mode syntax.
We will add an information about that in doc.


On Thursday, May 12, 2016 at 5:05:30 PM UTC+2, Rob Moore wrote:
Reply all
Reply to author
Forward
0 new messages