I have created a database called 'rodrigo-contatos' using the following code:
var mongojs = require('mongojs');
var db = mongojs('rodrigo-contatos', ['rodrigo-contatos']);
In an attempt to search the database, I am using the findOne method from mongojs. Here is the specific code:
app.get('/detalhesContato/:id', function(req, res){
var id = req.params.id;
console.log(id);
db.contatos.findOne({_id: mongojs.ObjectId(id)}, function(err, doc) {
console.log(err);
res.json(doc);
});
Even though console.log(id)
shows that the id is correct, the findOne method does not seem to be working as expected.
The following output was logged for the id: "567a16ba28dee028f4a8ad78"
An error occurred: TypeError: Cannot read property 'findOne' of undefined at /Users/Michel/Documents/AngularProjects/RodrigoBranasListaTelefonica/server.js:48:12"