If you do not specify a collection, this option copies all collections in the specified database or instance to the dump files. collection: Specifies a collection to backup. a connection string while also using -db and specifying conflicting information will result in an error. If you do not specify a database, mongodump collects from all databases in this instance.Īlternatively, you can also specify the database directly in the URI connection string i.e. db: Specifies the database to take a backup from. If you do not specify an authentication database or a database to export, mongodump assumes the admin database holds the user's credentials. authenticationDatabase: Specifies the authentication database where the specified -username has been created. password: Specifies a password to authenticate to a MongoDB database that uses authentication. If it is a connection string you can use this option Specifies a username to authenticate to a MongoDB database that uses authentication. host: The source MongoDB hostname along with the port. Run this command in the source database server mongodump -host="hostname:port" \ -username="username" -password="password" \ -authenticationDatabase "admin" \ -db="db name" -collection="collection name" -query='json' \ -forceTableScan -v -gzip -out. We're going to use an existing utility program mongodump for creating the database backup. Migrating from an offline database in MongoDB Creating a backup Let's look at simple migration first before diving into the live scenario. This is very straight forward when the source database is not online because we know that there won't be any new documents created/updated during the migration process. Create a zipped backup of the existing data.Now, the basic steps to migrate data from one MongoDB to another would be: If you're coming here for the first time, please take a look at the prequel Self-Hosted MongoDB.Īlright then, picking from where we left off, let's get started with the data migration in MongoDB. The goal of this post is to learn about the various ways of data migration in MongoDB that can help us to write scripts that change your database by adding new documents, modifying existing ones.
0 Comments
Leave a Reply. |