This is my first node.js app, so bear with me :-) I had tutorials and examples working, but when I try to do it myself I get no data at all. And Im out of ideas to why.
This is my model:
const expenseSchema = mongodb.Schema({
_id: {
type: String
},
name: {
type: String
}
});
const expensecategory = module.exports = mongodb.model('expensecategory', expenseSchema);
module.exports.getExpense = function(parms, callback){
console.log('LETS GO!!!..: ' + parms);
// expensecategory.find({}, callback);
// expensecategory.findOne({ "_id": "OFFICE" }, callback);
// expensecategory.find({ "_id": "OFFICE" }, callback);
const query = {
_id: "OFFICE"
}
expensecategory.findOne(query, callback);
// I cannot get any data, no matter what I do
}
This is my Route
router.get('/property/:propertyID', function(req, res) {
console.log("property propertyID: " + req.params.propertyID);
const propertyID = req.params.propertyID;
console.log('Calling getTranslate: ' + propertyID);
Expense.getExpense(propertyID, (err, result) => {
if(err) throw err;
console.log('ERR? ' + err);
console.log('RESULT? ' + result);
if(!result){
return res.json({msg: 'Nothing Found!! ' + result});
} else {
res.json({success:'' + result})
console.log('SUCCESS!!: ' + result);
console.log('_id: ' + result._id);
console.log('name: ' + result.name);
}
});
});
And this is the result from my terminal window
The funny thing is that these two find something
expensecategory.find({}, callback);
expensecategory.findOne({ "_id": "OFFICE" }, callback);
But the data they find is null
I checked mongodb already and the table is ok with data: