2022-12-14

How to properly use MongoClient to handle two connections to two servers in C#

from time to time, I need to export data from one environment into another environment, each environment is on a different server with different authentication. For instance: I am building a script to export data from PROD env to import to UAT env.

So far my flow will be like this:

  • 1.var client_prod = new MongoClient(prod_connection_string);
  • 2.get collection using client_prod and then do some query, load data into memory
  • 3.var client_uat = new MongoClient(uat_connection_string);
  • 4.get collection using client_uat, do upsert.

People says the MongoClient should be a singleton in Application. So I feel my design is not appropriate. How to properly use the mongoClient to migrate data from one server to another server?

Many thanks



No comments:

Post a Comment