Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-2533

Unified topology : docs are wrong or unified topology is not working at all.

    • Type: Icon: Bug Bug
    • Resolution: Gone away
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 3.5.4
    • Component/s: None
    • Labels:

      I've spent a lot of hours in my project to try to make my application try to reconnect to mongo even if initial connections fails (because docker stack, unlike regular docker compose, does not and will never support the feature that makes a container waits for another). According to this issue https://jira.mongodb.org/browse/NODE-1643 useUnifiedTopology should fix my issue (right know I'm using home made solution (

      const db: Promise<Db> = new Promise(async (resolve, reject) => {
       let success = false;
       // @ts-ignore
       const client = new MongoClient(url, {
       useUnifiedTopology: true,
       poolSize: 10,
       });
      
       for (let i = 0; i < 100 && !success; i += 1) {
       try {
       logger.info(`[MongoClient] attempt number ${i} to connect succeeded `);
       success = true;
       resolve(client.db(dbname));
       } catch (error) {
       if ((i < 60 && i % 10 === 0) || (i > 60 && i < 600 && i % 60 === 0) || (i > 600 && i % 3600 === 0)) {
       logger.error(`[MongoClient] attempt number ${i} to connect failed `, error);
       }
       }
      
       await sleep(1000);
       }
      
      
       if (!success) reject();
      });

      ) but I have random bugs like "pool is draining new operations prohibited" so I guess I'm doing it wrong.

      So I went through this unclear document https://mongodb.github.io/node-mongodb-native/3.5/reference/unified-topology/ ("Our goal is to move towards code that looks more like the following:" is weird because I don't know if the code below is correct, I think that you should not put possibly invalid code that may be valid at some point if things go according to your plans, "NOTE: In upcoming minor versions useUnifiedTopology will default to true, and in the next major version of the driver this topology will outright replace the legacy topologies." but this note is already present in this document in the vesion 5.3 of mongodb). Anyway from my understanding of this unclear document I thought CONNECT was not to be used anymore yet this code :

       

      const client = new MongoClient(url, {
       useUnifiedTopology: true,
       poolSize: 10,
      });
      client.db.(dname);
      

       

      gives the error MongoClient must be connected before calling MongoClient.prototype.db

       

      I'm using standalone mongo server (for my development local server, and online staging servers, I'll use replica set for production live server) 

       

            Assignee:
            matt.broadstone@mongodb.com Matt Broadstone
            Reporter:
            xd111@hotmail.fr Ilan Schemoul
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: