private void getUsersWithin24Hours(String id, Map < String, Object > payload) throws JSONException {
JSONObject json = new JSONObject(String.valueOf(payload.get("data")));
Query query = new Query();
query.addCriteria(Criteria.where("user_id").is(id).and("timezone").in(json.get("timezone")).and("gender").in(json.get("gender")).and("locale").in(json.get("language")).and("time").gt(getDate()));
mongoTemplate.getCollection("user_log").distinct("user_id", query.getQueryObject());
}
I was going to make a request and get the result from mongodb, and I succeeded in the mongo terminal command:
db.getCollection('user_log').find({"user_id" : "1", "timezone" : {$in: [5,6]}, "gender" : {$in : ["male", "female"]}, "locale" : {$in : ["en_US"]}, "time" : {$gt : new ISODate("2017-01-26T16:57:52.354Z")}})
but from java, when I tried, it gave me the error below.
org.bson.codecs.configuration.CodecConfigurationException: cannot find codec for class org.json.JSONArray
What is the perfect way to do this?
Hint: I actually think that an error has occurred in my code for this part of json.get ("time zone"). because it contains an array. When I use hardcode string arrays, this code works
source
share