这是我的第一个node.js应用,所以忍受我:-) 我有教程和示例工作,但当我尝试自己做,我根本没有数据。我想出了原因。
这是我的模特:
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
}
这是我的路线
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);
}
});
});
的结果
有趣的是,这两个人找到了什么
expensecategory.find({},callback);
expensecategory.findOne({" _id":" OFFICE"},回调);
但是他们找到的数据是空的
我已经检查了mongodb,表格没有数据: