Reputation: 17468
I want to export the first 1-100000th records from a collections.
I know I can type > db.mycollection.find({}).limit(1000000)
, but it is just get the data, the data need to be exported as json file.
Sample data
> db.minibars.find({}).limit(3)
{ "_id" : ObjectId("575fd03f6a6253c0b30dd54c"), "Symbol" : "MSFT", "Timestamp" : "2009-08-24 09:30", "Day" : 24, "Open" : 24.41, "High" : 24.42, "Low" : 24.31, "Close" : 24.31, "Volume" : 683713 }
{ "_id" : ObjectId("575fd0406a6253c0b30dd54d"), "Symbol" : "MSFT", "Timestamp" : "2009-08-24 09:31", "Day" : 24, "Open" : 24.32, "High" : 24.33, "Low" : 24.28, "Close" : 24.3, "Volume" : 207651 }
{ "_id" : ObjectId("575fd0406a6253c0b30dd54e"), "Symbol" : "MSFT", "Timestamp" : "2009-08-24 09:32", "Day" : 24, "Open" : 24.29, "High" : 24.33, "Low" : 24.29, "Close" : 24.31, "Volume" : 230729 }
How can I do that ?
Upvotes: 5
Views: 3156
Reputation: 2031
Look at the documentation here: https://docs.mongodb.com/manual/reference/program/mongoexport/
You're looking for mongoexport
Example:
mongoexport --db yourdb --collection mycollection --limit 100000 --out data.json
Upvotes: 7