Mongodb export json without _id
I am using mongoexport to export some data into .json formatted file, however the document has a large size overhead introduced by _id:IDVALUE tuples. Show I found a similar post Is
there a way to retrieve data from MongoDB without the _id field? on how to omit the _id field when retrieving data from mongo, but not exporting. It is suggested to use: Please suggest what is the proper way of doing this, or should I revert to using some post-export techniques? Thanks
asked Oct 19, 2012 at 14:13
There appears to be no way
to exclude a field (such as Here's an alternative that has worked for me on moderate sized databases:
On a large database (many millions of records) it can take a while and running this will affect other operations people try to do on the system: answered May 7, 2013 at 18:17
quux00quux00 12.7k9 gold badges56 silver badges68 bronze badges This works:
answered Apr 18, 2018 at 9:05
4 Pipe the output of
Update: adding link to jq. answered Oct 9, 2020 at 11:05
sebastiansebastian 1,3381 gold badge15 silver badges22 bronze badges I know you specified you wanted to export in JSON but if you could substitute CSV data the native mongo export will work, and will be a lot faster than the above solutions
Peter Perháč 20.2k21 gold badges117 silver badges151 bronze badges answered Aug 31, 2015 at 15:35
A_funsA_funs 1,2082 gold badges17 silver badges31 bronze badges
With
ramda-cli stripping the
answered Jun 1, 2015 at 17:53
raineraine 1,59114 silver badges12 bronze badges 2 I applied quux00's solution but It will be better to use the following line instead:
answered Aug 27, 2014 at 15:42
noletonoleto 1,42416 silver badges12 bronze badges
If you have some query to execute change answered Jan 20, 2016 at 3:06
xringxring 7082 gold badges8 silver badges27 bronze badges The simplest way to exclude the sub-document information such as the "_id" is to export it as a csv, then use a tool to convert the csv into json. answered Dec 28, 2013 at 6:38
MattMatt 9251 gold badge9 silver badges19 bronze badges mongoexport can not omit "_id" sed is a powerful command to do it:
The original answer is from Exclude _id field using MongoExport command answered Apr 13, 2018 at 2:28
KiwenLauKiwenLau 2,40417 silver badges23 bronze badges Just use --type=csv option in mongoexport command.
For MongoDb version 3.4, you can use --noHeaderLine option in mongoexport command to exclude the field header in csv export too. For Detail: https://docs.mongodb.com/manual/reference/program/mongoexport/ answered Oct 30, 2019 at 4:09
SamanSaman 1932 silver badges8 bronze badges export into a file and just use replace empty value using Regular expression, in my case
I used
Afsanefda 2,8396 gold badges33 silver badges69 bronze badges answered Apr 25, 2020 at 21:28
Have you tried specifying your fields with the For maintainability you can also write your fields into a seperate file and use answered Oct 19, 2012 at 14:33
zemircozemirco 15.8k8 gold badges60 silver badges93 bronze badges 3 How do I export data from MongoDB to JSON?Click on execute to export MongoDB data in JSON format using Studio3T.. Source: Make sure the source is entered correctly.. Format Option: Choose JSON-mongo shell/ JSON-mongoexport.. Target: Choose between clipboard/file & make sure the file path is defined.. What is the difference between Mongodump and Mongoexport?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.
How do I export a robo 3t collection?On the menu of Mongo Compass select Collection-> export collection, and you can select the fields to export, and the file to export the result, previously you can specify the query.
How do I export data from MongoDB?So, to export data from the MongoDB database, MongoDB provides a command-line tool known as mongoexport. Using this tool you can exports data of a collection in JSON or CSV(comma-separated value) format. Moreover, we can also use features like limit and sort on a collection while exporting the data.
|