Dinesh
Dinesh

Reputation: 2066

Date based Query MongoDB Collection

We have huge MongoDB with 70 Million records as of today. every day almost 1 Million records will be inserted in to this database. each document in the collection will have following data

{
    "_id" : ObjectId("5447f506e4b081e36588b006"),    
    "time" : "2014-10-22T15:16:32.000Z", 
    "created" : "2014-10-22T15:24:39.847Z", 
    "type" : "system",
    "upload" : "2"
}

every day we have to run some jobs to process the data daily basis. when we run the jobs, we will save the last documents details in our status log. When we the job next time, we will have to get the created time from this record, extract all the documents after this date from the MongoDB. i got struck in writing query for extracting the documents which are not processed i.e. fetch the records after the date saved in log. Can somebody help to write the MongoDB query for this?

Upvotes: 0

Views: 334

Answers (1)

code_monk
code_monk

Reputation: 10130

assuming you have a variable called $date:

db.collection.find({created: {"$gt": $date}})

http://docs.mongodb.org/manual/reference/operator/query/gt/

Upvotes: 1

Related Questions