0

How do I write a MongoDB shell query that will return the documents for all objects created after a specific date?

Collections like:

{
"_id" : ObjectId("59918c9014450171039b7e1f"),
"cont_id" : "59918c9014450171039b7e1d",
"systemdate" : ISODate("2017-07-25T00:09:00.567Z"),
}

db.itemtable.count({"systemdate" : { $gte: ISODate("2017-07-25T00:00:00.000Z")}})

Returns - 15210

db.itemtable.count({'_id': {'$gt' : ObjectId("59918c9014450171039b7e1f")}})

Returns - 987652

Thanks! Bharathi

Bharathiraja S
  • 679
  • 4
  • 12
  • 26

1 Answers1

0

db.itemtable.find({"systemdate" : { $gte: ISODate("2017-07-25T00:00:00.000Z")}}).count() returns count of those documents.

If you want cursor to those documents, use just find db.itemtable.find({"systemdate" : { $gte: ISODate("2017-07-25T00:00:00.000Z")}})

JJussi
  • 1,540
  • 12
  • 12
  • thank you both! We all know ObjectId contains the current timestamp along with someother details, any way to find out the ObjectId greater than (>) "some id", which list down the ObjectId's created after specific timestamp `db.itemtable.count({'_id': {'$gt' : ObjectId("59918c9014450171039b7e1f")}})` – Bharathiraja S Aug 16 '17 at 07:16
  • Take some time stamp as Unix timestamp `08/16/2017 @ 8:48am (UTC)` is 1502873284 what translates to 0x599406C4. Then you just ` db.data.find({_id:{$gt:ObjectId("599406c40000000000000000")}})` – JJussi Aug 16 '17 at 09:36