Trade-offs to consider when storing binary data in MongoDB
4 stars based on
This document provides an overview of the import and export programs included in the MongoDB distribution. These tools are useful when you want to backup or export a portion of your data without capturing mongodb bindata methods state of the entire database, or for simple mongodb bindata methods ingestion cases.
For more complex data migration tasks, you may want to write your own import and export scripts using a client driver to interact with the database itself. For disaster recovery protection and routine database backup operation, use full database instance backups. Because these tools primarily operate by interacting mongodb bindata methods a running mongod instance, they can impact the performance of your running database.
Not only do these processes create traffic for a running database instance, they also force the database to read all data through memory. As a result data exported or imported with these tools may lose some measure mongodb bindata methods fidelity. Additionally, consider the following references for commands addressed in this document:. If maintaining type fidelity is important, consider writing a data import and export system that does not force BSON documents into JSON form as part of the process.
For resilient and non-disruptive backups, use a file system or block-level disk snapshot function, such as the methods described in mongodb bindata methods MongoDB Backup Methods document. By contrast, use import and export tools to backup a small subset of your data or to move data to or from a 3rd party mongodb bindata methods. These backups may capture a small crucial set of data or a frequently modified section of data, for extra insurance, or for ease of access.
No matter how you decide to import or export your data, consider the following guidelines:. The mongoimport and mongoexport documents contain complete documentation of these tools. If you have questions about the function and parameters of these tools not covered here, please refer to these documents. If you want to simply copy a database or collection mongodb bindata methods one instance to another, consider using the copydbcloneor cloneCollection commands, which may be more suited to this task.
The mongo shell provides the db. These tools may also be useful for importing data into a MongoDB database from third party applications. With the mongoexport utility you can create a backup file.
In the most simple invocation, the command takes the following form:. This will export all documents in the collection named collection into the file collection. Without the output specification i. Enclose the query in single mongodb bindata methods e.
The resulting documents will return on standard output. See the following example:. This reads the data files directly. This locks the data directory to prevent conflicting writes. The mongod process must not be running or attached to these data files when you run mongoexport in this configuration.
Consider the following example:. On any mongoexport command you may, as above specify username and password credentials as above. To restore a backup taken with mongoexport. Most of the arguments to mongoexport also exist for mongoimport. Consider the following command:. This imports the contents of the file collection. This option will cause some performance impact depending on mongodb bindata methods configuration.
You can specify the database option --db to import these documents to a particular database. The mongod process must not be running or attached to these data files when you run mongoimport in this configuration. Licensed under Creative Commons. Version Select Version 3. Warning Because these tools primarily operate by interacting with a running mongod instance, they can impact the performance of your running database.
Additionally, consider the following references for commands addressed in this document: Map-Reduce and Aggregation Concepts. No matter how you decide to import or export your data, consider the following mongodb bindata methods Label files so that you can identify what point in time the export or backup reflects.
Labeling should mongodb bindata methods the contents of the backup, and reflect the subset of the data corpus, captured in the backup or export. Do not create or apply exports if the backup process itself will have an adverse effect on a production system.
Make sure that they reflect a consistent data state. Export or backup processes can impact data integrity i. Test backups and exports by restoring and importing to ensure that the backups are useful. See also The mongoimport and mongoexport documents contain complete documentation of these tools.
In the most simple invocation, the command takes the following form: Consider the following command: