0

All of the documents in my collection contain a string field, "sourceTimeStamp" which looks like for example, 2018-11-15T14:20:06. I am trying to come up with a way to get a particular day's worth of data. I can access the data directly from RoboMongo using:

db.getCollection('archive_Nov_15_8pm_2018').find({ "tfms_object.sourceTimeStamp" : { $regex : /^2018-11-25*/}})

This returns many documents. But I need to do this using JAVA so I tried this:

DBCollection collection = db.getCollection(ARCHIVE_COLLECTION);
Pattern pat = Pattern.compile("^2018-11-15.*");
BasicDBObject query = new BasicDBObject("departureTime", pat);
List<BasicDBObject> obj = new ArrayList<BasicDBObject>();
query.put("$and", obj);

However, I get 0 documents returned. Any ideas?

alexrnov
  • 2,346
  • 3
  • 18
  • 34
J. Ike
  • 19
  • 5
  • Sorry, the 3rd line should read: BasicDBObject query= new BasicDBObject("tfms_object.sourceTimeStamp", pat); – J. Ike Nov 26 '18 at 21:42
  • 1
    Just edit it https://stackoverflow.com/posts/53489473/edit – wp78de Nov 26 '18 at 22:37
  • Seems to be duplicated: https://stackoverflow.com/questions/8835757/return-query-based-on-date – Igor Nov 26 '18 at 23:40
  • Possible duplicate of [return query based on date](https://stackoverflow.com/questions/8835757/return-query-based-on-date) – Igor Nov 26 '18 at 23:41

0 Answers0