Using JavaScript and Mongoose, I want to export all of the documents of a certain document class to a file (eg, a JSON or CSV file), and I also want to import (ie, "load") the contents of such a file into a database. How can I accomplish this?
From mongoDB docs:
EXPORT / BACKUP
To backup data from a mongod instance running on the same machine and on the default port of 27017, use the following command:
mongodump
You can also specify the --host and --port of the MongoDB instance that the mongodump should connect to. For example:
mongodump --host=mongodb.example.net --port=27017
mongodump will write BSON files that hold a copy of data accessible via the mongod listening on port 27017 of the mongodb.example.net host. See Create Backups from Non-Local mongod Instances for more information.
To specify a different output directory, you can use the --out or -o option:
mongodump --out=/data/backup/
IMPORT / RESTORE
To use mongorestore to connect to an active mongod, use a command with the following prototype form:
mongorestore --port=<port number> <path to the backup>
Consider the following example:
mongorestore dump-2013-10-25/
MongoDB Docs: Check
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.