I have a collection of documents I'd like to pull a subset created after a certain point in time. I understand the timestamp of creation is encoded in each documents ObjectID (assuming they are auto generated). I see the ObjectId has a getTimestamp method that returns that portion of the ObjectID as an ISOdate.

I'm not very fluent in mongo and am having trouble constructing this seemingly simple query.

For bonus points, once I figure out the "where clause", if you will, I'm wanting to select a single field from the documents using mongodump or what ever else might be available to export the results to a text file via a mongo shell.

1 Answer 1


The general approach was to fabricate an ObjectID with the time stamp prefix of what I wanted. The general query looked like

db.mycol.find({_id: {$gte:ObjectId("50b7feb00000000000000000")} }, {fieldIWant:1})

The corresponding mongoexport cmd for a json output file was

 mongoexport -d mydb -c mycol -q '{_id: {$gte:ObjectId("50b7feb00000000000000000")} }' -f 'fieldIWant' > myFile.json

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.