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
– Costamilam
Post the code on your question... Can’t help without seeing where the bug is!
– Lucas Bittencourt
I just modified the question by entering the code.
– Ronaldo Mendes