Skip to content

Instantly share code, notes, and snippets.

@lslucas
Last active December 15, 2015 10:49
Show Gist options
  • Save lslucas/5248041 to your computer and use it in GitHub Desktop.
Save lslucas/5248041 to your computer and use it in GitHub Desktop.
Mongo Import a single json file to a new collection
#import a single json file
$ mongoimport -h 127.0.0.1 -c subprovider -db techtravel --file subprovider.json
#import csv file
$ mongoimport -d mydb -c things --type csv --file locations.csv --headerline
#export a single collection
$ mongoexport --db techtravel --collection subprovider --out /var/www/techtravel/storage/database/2013-04-03/subprovider.json
#export a single collection but specific data from that collection
mongoexport --db admin -cprovider --out provider-new.json -q '{"hash_id":{"$in" :[ "ryR4eGnq", "R4MnaK8A", "gMG859E8" ]}}'
#dump all databases
$ mongodump --out /var/www/project/storage/database/date
#restore all databases dumped
$ mongorestore /var/www/project/storage/database/date
#dump all collections from a single db
mongodump -d dbname -o storage/database/dateorsomething/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment