0

I was going to get distinct values form collection. I stored time as follows:

"time" : ISODate("2017-01-26T09:46:26.523Z")

new ISO8601DateFormat() is not working, that gives me below error

org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class com.fasterxml.jackson.databind.util.ISO8601DateFormat.

My code is looks like below.

Query query = new Query();
query.addCriteria(Criteria.where("user_id").is(id).and("time").gt(new ISO8601DateFormat()));
mongoTemplate.getCollection("user_log").distinct("timezone", query.getQueryObject())

My mongodb terminal command is follows and it works perfectly.

db.user_log.find({ "user_id" : "1" , "time" : { "$gt" : new ISODate("2017-01-25T00:16:15.184Z")}})

What is correct way to approach when I access from java?

Januka samaranyake
  • 2,385
  • 1
  • 28
  • 50

1 Answers1

1
Instant instant = Instant.parse("2017-01-25T00:16:15.184Z"); 
Date time = Date.from(instant);

Replace your time criteria with below

and("time").gt(time)
s7vr
  • 73,656
  • 11
  • 106
  • 127