[MongoDB]: Nested documents

Please refer my previous post for the background of the issues with nested documents at Issues-with-Nested-documents

However, versions prior to 2.8-rc1 doesn’t handle nested documents properly – neither mongoimport nor mongoexport.

But the good news is that both work with nested documents in version 2.8.

Download release 2.8-rc1 and use the mongoimport/mongoexport utilities from that version.
But note that 2.8 is a release candidate only and should not be used for production purposes. Using it for the utilities is okay.

Here’s an example of a working set:

The documents
{
“_id”: “\\hostname\\hostname_files”,
“Files”: {
“FileName”: “hostname_file11.db”,
“Extension”: “db”,
“Size”: 500
},
“SubFolders”: “Subfolder2”
}
{
“_id”: “\\hostname\\hostname_file1”,
“Files”: {
“FileName”: “hostname_file22.db”,
“Extension”: “db”,
“Size”: 250
},
“SubFolders”: “Subfolder1”
}
Mongoexport :-
===========

mongoexport –csv –db test -c users -f ‘_id,Files.FileName,Files.Extension,Files.Size,SubFolders’ -o file.csv

CSV file – note single \ and no quotes!
_id,Files.FileName,Files.Extension,Files.Size,SubFolders
\hostname\hostname_file1,hostname_file22.db,db,250,Subfolder1
\hostname\hostname_files,hostname_file11.db,db,500,Subfolder2

Mongoimport:-
===========

mongoimport –db test –collection users –type csv –headerline –file file.csv

  • Ask Question