Mongo Export

103 views
Skip to first unread message

Amar

unread,
Sep 9, 2012, 8:14:58 AM9/9/12
to mongod...@googlegroups.com
Hi All,

I am new to MongoDB. When I am using "--directoryperdb" option in MongoExport I am getting an exception.

Here is the query what I am using
mongoexport.exe -f <FieldNames> --csv --dbpath d:\devhome\tools\mongodb\data\db --directoryperdb

Error:
no collection specified!
Export MongoDB data to CSV, TSV or JSON files.

After that I specified a collection name, now my query is
mongoexport.exe -f <FieldNames> --csv --dbpath d:\devhome\tools\mongodb\data\db --directoryperdb -c Person
Now I am getting
exported 0 records
Sun Sep 09 17:36:14 dbexit:
Sun Sep 09 17:36:14 [tools] shutdown: going to close listening sockets...
Sun Sep 09 17:36:14 [tools] shutdown: going to flush diaglog...
Sun Sep 09 17:36:14 [tools] shutdown: going to close sockets...
Sun Sep 09 17:36:14 [tools] shutdown: waiting for fs preallocator...
Sun Sep 09 17:36:14 [tools] shutdown: closing all files...
Sun Sep 09 17:36:14 [tools] closeAllFiles() finished
Sun Sep 09 17:36:14 [tools] shutdown: removing fs lock...
Sun Sep 09 17:36:14 dbexit: really exiting now

Here my doubt is how can we use --directoryperdb option. Could anyone help me on this. I stuck over here.

Note: If I remove --directoryperdb I am able to export one collection(If I specified dbname and collection name). How can we export all databases using MongoExport.

Thanks & Regards,
Amar







मैं एक भारतीय बेवकूफ हूँ

unread,
Sep 9, 2012, 8:17:27 AM9/9/12
to mongod...@googlegroups.com


Amar wrote:
> no collection specified!

Not clear enough?

Stephen Steneker

unread,
Sep 9, 2012, 8:38:20 AM9/9/12
to mongod...@googlegroups.com
I am new to MongoDB. When I am using "--directoryperdb" option in MongoExport I am getting an exception.

Hi,

The --directoryperdb option is meant to be used in conjunction with the --dbpath option (which read from the data files directly).

You would only need to use --directoryperdb on a mongoexport if this option was also used in your mongod config.

More typical usage would be to omit the --dbpath and connect to the mongod server instead. 


Here is the query what I am using
mongoexport.exe -f <FieldNames> --csv --dbpath d:\devhome\tools\mongodb\data\db --directoryperdb

 The mongoexport tool is used to export a single collection to CSV, TSV, or JSON so you must also specify one with -c:

   mongoexport.exe -f <FieldNames> --csv  -c collection

 
Note: If I remove --directoryperdb I am able to export one collection(If I specified dbname and collection name). How can we export all databases using MongoExport.

If you want to export all databases, you should instead be using mongodump / mongorestore:
   http://www.mongodb.org/display/DOCS/Import+Export+Tools#ImportExportTools-mongodumpandmongorestore

Cheers,
Stephen

amar shiva

unread,
Sep 9, 2012, 9:02:51 AM9/9/12
to mongod...@googlegroups.com
Hi Stephen,

Thanks for your reply. So what I understand was MongoExport will export one collection(from one database) at a time. Is it right stephen..?????? 

So if we want to export all the databases we need to use "MONGO DUMP" right??????

So if we export one collection at a time when this  --directoryperdb come into picture. I didn't understand clearly. Could you please explain with one example please.

Thanks & Regards,
Amar


--
You received this message because you are subscribed to the Google
Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com
To unsubscribe from this group, send email to
mongodb-user...@googlegroups.com
See also the IRC channel -- freenode.net#mongodb

Stephen Steneker

unread,
Sep 9, 2012, 10:26:34 PM9/9/12
to mongod...@googlegroups.com
Thanks for your reply. So what I understand was MongoExport will export one collection(from one database) at a time. Is it right stephen..?????? 

Yes, mongoexport is for exporting one collection to a text format (CSV, TSV, JSON).


So if we want to export all the databases we need to use "MONGO DUMP" right??????

If you want to backup and restore all of the collections and databases, mongodump/mongorestore are the correct programs to use.

If you want to export each collection to a text format, you can use mongoexport but you will have to call it once for every collection.
 

So if we export one collection at a time when this  --directoryperdb come into picture. I didn't understand clearly. Could you please explain with one example please.

You would only want to use this option if all of the following are true:

 - you are using --directoryperdb in your mongod configuration
 - you want to use --dbpath from mongoexport/mongodump (which reads the data files directly instead of connecting to the mongo server)
 - you do not have a mongod currently using those db files

This is very likely *not* an option you want to use, which is why I suggested you should not include it.

Cheers,
Stephen

amar shiva

unread,
Sep 10, 2012, 7:05:40 AM9/10/12
to mongod...@googlegroups.com
Hi Stephen,

Thanks for your detailed explanation.

Thanks & Regards,
Amar


Cheers,
Stephen

--
330.gif
Reply all
Reply to author
Forward
0 new messages