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

Getting deprecated warnings

    • Type: Icon: Task Task
    • Resolution: Works as Designed
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 3.1.12
    • Component/s: None
    • Environment:
      Docker container mongo:latest.

       
       I've posted this problem in Stackoverflow (https://stackoverflow.com/questions/54639778/why-am-i-getting-this-deprecated-warning-mongodb/54639983?noredirect=1#comment96081778_54639983).

      ---------
      I'm working with MongoDB in NodeJS,

      const { MongoClient, ObjectId } = require("mongodb");
      
      const MONGO_URI = `mongodb://xxx:xxx@xxx/?authSource=xxx`; // prettier-ignore
      
      class MongoLib {
      
        constructor() {
          this.client = new MongoClient(MONGO_URI, {
            useNewUrlParser: true,
          });
          this.dbName = DB_NAME;
        }
      
        connect() {
          return new Promise((resolve, reject) => {
            this.client.connect(error => {
              if (error) {
                reject(error);
              }
              resolve(this.client.db(this.dbName));
            });
          });
        }
        async getUser(collection, username) {
          return this.connect().then(db => {
            return db
              .collection(collection)
              .find({ username })
              .toArray();
          });
        }
      }
      
      let c = new MongoLib();
      
      c.getUser("users", "pepito").then(result => console.log(result));
      c.getUser("users", "pepito").then(result => console.log(result));
      

      and when the last c.getUser statement is executed (that's to say, when I make a SECOND connectio) Mongodb outputs this warning:

      the options [servers] is not supported
      the options [caseTranslate] is not supported
      the options [username] is not supported
      the server/replset/mongos/db options are deprecated, all their options are supported at the top level of the options object [poolSize,ssl,sslValidate,sslCA,sslCert,sslKey,sslPass,sslCRL,autoReconnect,noDelay,keepAlive,keepAliveInitialDelay,connectTimeoutMS,family,socketTimeoutMS,reconnectTries,reconnectInterval,ha,haInterval,replicaSet,secondaryAcceptableLatencyMS,acceptableLatencyMS,connectWithNoPrimary,authSource,w,wtimeout,j,forceServerObjectId,serializeFunctions,ignoreUndefined,raw,bufferMaxEntries,readPreference,pkFactory,promiseLibrary,readConcern,maxStalenessSeconds,loggerLevel,logger,promoteValues,promoteBuffers,promoteLongs,domainsEnabled,checkServerIdentity,validateOptions,appname,auth,user,password,authMechanism,compression,fsync,readPreferenceTags,numberOfRetries,auto_reconnect,minSize,monitorCommands,retryWrites,useNewUrlParser]
      

      But I'm not using any deprecated options. Any ideas?

      EDIT

      After a little discussion with molank in the comments, it looks like open several connections from the same server is not a good practice, so maybe that's what the warning is trying to say (badly I think). So if you have the same problem, save the connection instead of the mongo client.

            Assignee:
            daniel.aprahamian@mongodb.com Daniel Aprahamian (Inactive)
            Reporter:
            antonio Antonio
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: