Last active
January 2, 2016 19:09
-
-
Save nas/8348774 to your computer and use it in GitHub Desktop.
importing and exporting mongo db/collection in various formats
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary | |
====== | |
* Import database | |
mongorestore -h host:port -d experimental2 -u <user> -p <password> <input db directory> | |
* Export database | |
mongodump -h host:port -d experimental2 -u <user> -p <password> -o <output directory> | |
* Import collection | |
mongorestore -h host:port -d experimental2 -u <user> -p <password> <input .bson file> | |
* Export collection | |
mongodump -h host:port -d experimental2 -c <collection> -u <user> -p <password> -q <query else will export full collection> -o <output directory> | |
JSON | |
==== | |
* Import collection | |
mongoimport -h host:port -d experimental2 -c <collection> -u <user> -p <password> --file <input file> | |
* Export collection | |
mongoexport -h host:port -d experimental2 -c <collection> -u <user> -p <password> -q <query else will export full collection> -o <output file> | |
CSV | |
=== | |
* Import collection | |
mongoimport -h host:port -d experimental2 -c <collection> -u <user> -p <password> --file <input .csv file> --type csv --headerline | |
* Export collection | |
mongoexport -h host:port -d experimental2 -c <collection> -u <user> -p <password> -q <query else will export full collection> -o <output .csv file> --csv -f <comma-separated list of field names> | |
Date query e.g. | |
* var end = new Date("01/23/2014 00:00:00");end.getTime() #=>1390435200000 | |
* -q {created_at: {\$lt: new Date(1390435200000) }}" | |
* db.coll.count({created_at: {$lt: new Date(1390435200000) }}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment