Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

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.

share|improve this question

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
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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