Typeerror: this. _Connection.open is not a Function

Asked

Viewed 608 times

0

I am doing activity to learn about Nodejs and Mongodb, and during the project, I have the error below:

TypeError: this._connection.open is not a function

As I am still in the learning phase, I could not understand well, but it seems to me that the problem is with the "open".

The User file has the following code:

function UsuariosDAO(connection){
    this._connection = connection();
}

UsuariosDAO.prototype.inserirUsuario = function(usuario){
    this._connection.open( function(err, mongoclient){
        mongoclient.collection("usuarios", function(err, collection){
            collection.insert(usuario);

            mongoclient.close();
        });
    });
}

module.exports = function(){
    return UsuariosDAO;
}

And part of the.js registration file that appears related to the error:

var connection = application.config.dbConnection;
var UsuariosDAO = new application.app.models.UsuariosDAO(connection);

UsuariosDAO.inserirUsuario(dadosForm);

Finally, what would be the best solution to this problem?

  • The error is clear, the property open is not a function, so calling it causes this exception. Can’t help more than this without having the rest of the code related to _connection

  • Post the code on your question... Can’t help without seeing where the bug is!

  • I just modified the question by entering the code.

1 answer

3


I was able to resolve after removing the latest version of the Mongodb npm module and installing the following version:

npm install --save [email protected]

Browser other questions tagged

You are not signed in. Login or sign up in order to post.