TypeError: this._connection.open is not a function

-1

I'm 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 it well, but it seems to me that the problem is with the "open".

The UsersDAO 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 cadastro.js file that appears listed in the error:

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

UsuariosDAO.inserirUsuario(dadosForm);

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

    
asked by anonymous 30.12.2018 / 01:01

1 answer

0

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

npm install --save [email protected]
    
03.01.2019 / 20:46