'Mongodb snapshot node

I am getting an error when using mongodb-snapshot.

    async function dumpMongo2Localfile() {
  const mongo_connector = new MongoDBDuplexConnector({
      connection: {
          uri: `mongodb://${process.env.DB_USER}:${process.env.DB_PASS}@cluster0.5i5dp.mongodb.net:27017`,
          dbname: 'myDB',
      },
  });

  const localfile_connector = new LocalFileSystemDuplexConnector({
      connection: {
          path: './backup.tar',
      },
  });

  const transferer = new MongoTransferer({
      source: mongo_connector,
      targets: [localfile_connector],
  });

  for await (const { total, write } of transferer) {
      console.log(`remaining bytes to write: ${total - write}`);
  }
}

My code is like this and I am calling this function below.

exports.backupDB=async(req,res,next)=>{
  dumpMongo2Localfile();
  
}

The error it gives is as follows

MongoServerSelectionError: getaddrinfo ENOTFOUND cluster0.5i5dp.mongodb.net
    at Timeout._onTimeout (E:\ecommerce\node_modules\mongodb-snapshot\node_modules\mongodb\lib\core\sdam\topology.js:438:30)
    at listOnTimeout (node:internal/timers:568:17)
    at processTimers (node:internal/timers:510:7) {
  reason: TopologyDescription {
    type: 'Single',
    setName: null,
    maxSetVersion: null,
    maxElectionId: null,
    servers: Map(1) {
      'cluster0.5i5dp.mongodb.net:27017' => ServerDescription {
        address: 'cluster0.5i5dp.mongodb.net:27017',
        error: Error: getaddrinfo ENOTFOUND cluster0.5i5dp.mongodb.net
            at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:72:26) {
          name: 'MongoNetworkError'
        },

I don't know how i can fix it. I tried all the ways but none of them worked.



Solution 1:[1]

That does not look like a connection string from Atlas. You can get one from the connect button on your cluster.

https://docs.atlas.mongodb.com/connect-to-cluster/#connect-to-a-cluster

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sagar