I use the following code on Robo 3T (a mongodbGUI software)
db.getCollection("json").find({"time":{$gte:1528771648859,$lte:1528771698869}},{"data":{$elemMatch :{"deviceid":456789123}}})
can get the results I want, but I can"t use the code
BasicDBObject query = new BasicDBObject();
query.put("time",(new BasicDBObject("$gte",1528771648859L)).append("$lte",1528771698869L));
query.put("data",new BasicDBObject("$elemMatch",new BasicDBObject("deviceid",456789123)));
DBCursor dbCursor = mongoTemplate.getCollection("json").find(query);
I would like to ask you guys, how can I use java to implement the above sql statement and return the correct results?