H
H
huhguz2018-10-28 19:34:59
JavaScript
huhguz, 2018-10-28 19:34:59

How to fix bad input string error when connecting mongodb?

When connecting the mongodb database, I get an error in my project. The most interesting thing is that if I create a separate file in which I execute the connection code, there will be no error. I even connected the same dependencies as in the main project, there was still no error, it is only in the main project file, the code of which I cannot post.
Here is my code to connect to the database:

mongoClient.connect("mongodb://localhost:27017/", {
        useNewUrlParser: true
    }, function(err, client) {

        if (err) {
            return console.log(err);
        }
        const db = client.db("db");
        const collection = db.collection("users");
        // взаимодействие с базой данных
       client.close();
    });

Error text:
internal/crypto/hash.js:62
  if (!this._handle.update(data, encoding || getDefaultEncoding()))
                    ^

TypeError: Bad input string
    at Hash.update (internal/crypto/hash.js:62:21)
    at new Connection (/var/www/www-root/data/www/evebot.su/node_modules/mongodb-core/lib/connection/connection.js:170:8)
    at _createConnection (/var/www/www-root/data/www/evebot.su/node_modules/mongodb-core/lib/connection/pool.js:1316:20)
    at /var/www/www-root/data/www/evebot.su/node_modules/mongodb-core/lib/connection/pool.js:1528:15
    at waitForAuth (/var/www/www-root/data/www/evebot.su/node_modules/mongodb-core/lib/connection/pool.js:1417:40)
    at /var/www/www-root/data/www/evebot.su/node_modules/mongodb-core/lib/connection/pool.js:1425:5
    at /var/www/www-root/data/www/evebot.su/node_modules/mongodb-core/lib/connection/pool.js:1278:23
    at process._tickCallback (internal/process/next_tick.js:61:11)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
grinat, 2018-10-28
@grinat

Invalid host or port:
https://github.com/mongodb-js/mongodb-core/blob/ma...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question