After obtaining the needed connection properties, accessing MongoDB data in PowerShell and preparing for replication consists of four basic steps.

Set the Server, Database, User, and Password connection properties to connect to MongoDB. To access MongoDB collections as tables you can use automatic schema discovery or write your own schema definitions. Schemas are defined in .rsd files, which have a simple format. You can also execute free-form queries that are not tied to the schema.

Loop through the MongoDB data, store the values, and use the Add-MySQL cmdlet to insert the data into the MySQL database, one row at a time. In this example, the table will need to have the same name as the MongoDB resource (restaurants) and to exist in the database.

You have now replicated your MongoDB data to a MySQL database. This gives you freedom to work with MongoDB data in the same way that you work with other MySQL tables, whether that is performing analytics, building reports, or other business functions.

Notes

Once you have connected to MongoDB and MySQL in PowerShell, you can pipe command results to perform the replication in a single line:

If you wish to replicate the MongoDB data to another database using another PowerShell module, you will want to exclude the Columns, Connection, and Table columns from the data returned by the Select-MongoDB cmdlet since those columns are used to help pipe data from one CData cmdlet to another: