how to give limit in mongoexport in mongodb

551 views
Skip to first unread message

Rahul Mehta

unread,
Oct 3, 2011, 8:09:28 AM10/3/11
to mongodb-user
I want to take backup of only 100 records from a collection how can i
give limit in query -q.

here what i tried giving limit but after giving limit in -q it is not
inserting any record.

mongoexport --host localhost --db test --collection foo -q
"{"limit":"1"}" > a.json
Please suggest how can i give limit number of record in mongoexport

http://www.mongodb.org/display/DOCS/mongoexport

Karl Seguin

unread,
Oct 3, 2011, 8:13:28 AM10/3/11
to mongod...@googlegroups.com
Can't, though there is a feature request for this at:

The only way I can think of is that you wrap it in a little script...write the documents you want to export to a placeholder collection (using ruby or something) and then export that.

Karl

Brandon Diamond

unread,
Oct 11, 2011, 10:27:47 AM10/11/11
to mongodb-user
Another option is to run the "limit 100" query in a shell script,
retrieve the min and max ObjectIDs in the range (noting that the top 4
bytes of an ObjectID are a timestamp) and then pass the corresponding
range query to mongoexport. A bit round-about but it'll work in a
pinch!

Hope this helps,
Brandon
Reply all
Reply to author
Forward
0 new messages