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
The Limit() Method To limit the records in MongoDB, you need to use limit() method. The method accepts one number type argument, which is the number of documents that you want to be displayed.
The maximum size an individual document can be in MongoDB is 16MB with a nested depth of 100 levels. Edit: There is no max size for an individual MongoDB database.
The maximum BSON document size is 16 megabytes. The maximum document size helps ensure that a single document cannot use excessive amount of RAM or, during transmission, excessive amount of bandwidth. To store documents larger than the maximum size, MongoDB provides the GridFS API.
mongoexport is a command-line tool that produces a JSON or CSV export of data stored in a MongoDB instance. mongodump is a utility for creating a binary export of the contents of a database.
mongoexport supports limit, so simply:
mongoexport --host localhost --db test --collection foo --limit 1 --out a.json
If you are using a *nix (or cygwin), you could use head -100
mongoexport --host localhost --db test --collection foo | head -100 > a.json
EDIT : as found on the mongodb mailing list, there is a feature request for this : https://jira.mongodb.org/browse/SERVER-2033
EDIT: this answer is more than 4y old. Mongodb has implemented a built-in feature, see other answers below.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With