Data export from MongoDB

112 views
Skip to first unread message

Narendrakumar Manica

unread,
Nov 9, 2015, 4:02:59 PM11/9/15
to mongodb-user
Hi all,

I am new to Mongo DB. a'm trying to export result document to CSV file but data in the csv is missed aligned because  some elements are not present in all the document.

I have attached the export Csv and also the NoSQL manager screenshot of table view.

Can someone suggest me how to export the data from Mongo without misalignment of data

Regards,
Naren
result.csv
Mongo_Sc1.JPG
Mongo_Sc2.JPG

John De Goes

unread,
Nov 9, 2015, 6:21:39 PM11/9/15
to mongodb-user

I'd suggest using SlamData to download because you can download collections, databases, and clusters in either JSON or CSV, uncompressed or compressed, with support for streaming / very large data files.

But just curious, CSV is not a great fit for MongoDB data. Why do you need the result to be in CSV?

Regards,

John

Tim Hawkins

unread,
Nov 9, 2015, 6:57:39 PM11/9/15
to mongod...@googlegroups.com

Hi Naren

Are you using mongoexport  with the "feilds" option, that should stop the missalignment on missing fields,  if it does not then it is a bug and you should report it on JIRA

--fields <field1[,field2]>, -f <field1[,field2]>
Specifies a field or fields to include in the export. Use a comma separated list of fields to specify multiple fields.

For csv output formats, mongoexport includes only the specified field(s), and the specified field(s) can be a field within a sub-document.

For JSON output formats, mongoexport includes only the specified field(s) and the _id field, and if the specified field(s) is a field within a sub-document, the mongoexport includes the sub-document with all its fields, not just the specified field within the document.

--fieldFile <filename>
An alternative to --fields. The --fieldFile option allows you to specify in a file the field or fields to include in the export and is only valid with the --type option with value csv. The file must have only one field per line, and the line(s) must end with the LF character (0x0A).

mongoexport includes only the specified field(s). The specified field(s) can be a field within a sub-document.


--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: http://www.mongodb.org/about/support/.
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at http://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/03f1ae5e-ec7d-4c6a-acdc-9a28705ec4c1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Asya Kamsky

unread,
Dec 6, 2015, 6:11:01 PM12/6/15
to mongodb-user
No matter how I tried, I could not reproduce what you are seeing.   I did mongoexport with similar schema multiple times with 2.6 and 3.0 versions and every time Excel opened the resultant CSV files with appropriate empty cells:


Maybe you can tell us exactly what command you used to export documents to CSV file and how you then loaded it into spreadsheet.   Also what version of MongoDB you are using.

I used (substitute your own set of fields after -f)

mongoexport -d dbname -c collname --type csv -f _id,create_date,modified_date,priority,parent_id,target_date,details  > export 303.csv

Inside the file first line has all the fields and then values are missing anywhere the field didn't exist (see two commas in a row):
_id,create_date,modified_date,priority,parent_id,target_date,details
ObjectId(5664bdd7d8a9239506be5590),2015-12-06T22:59:35.951Z,2015-12-06T22:59:35.951Z,Medium,TK0097553227,2015-12-06T22:59:35.951Z,text here
ObjectId(5664bde6d8a9239506be5591),2015-12-06T22:59:50.703Z,2015-12-06T22:59:50.703Z,High,,2015-12-06T22:59:50.703Z,text here
etc.

Asya



--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: http://www.mongodb.org/about/support/.
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at http://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/03f1ae5e-ec7d-4c6a-acdc-9a28705ec4c1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Asya Kamsky
Lead Product Manager
MongoDB
Download MongoDB - mongodb.org/downloads
Free MongoDB Monitoring - cloud.mongodb.com
Free Online Education - university.mongodb.com
Get Involved - mongodb.org/community
We're Hiring! - https://www.mongodb.com/careers
Reply all
Reply to author
Forward
0 new messages