【发布时间】:2018-02-13 23:11:42
【问题描述】:
我正在开发一个 Ionic-1 + nodejs + angular 应用程序。即使第一次调用更新数据库,我的 mongoDb findOneAndUpdate() 函数也会在每次调用时返回 true。
节点:
app.post('/booking', function (req, res) {
var collection = req.db.get('restaurant');
var id = req.body.id;
var status = req.body.status;
collection.findOneAndUpdate({status: status, id: id},{$set:{status:"booked"}}, function (e, doc) {
console.log(id, status);
if (e) {
console.log(e);
}
else if(!doc) {
res.send(false);
}
else {
res.send(true);
}
});
});
controller.js
$scope.bookMe = function(id){
var Obj = {status: "yes", id: id};
myService.booking(Obj).success(function(res){
console.log(Obj, "Checking status")
console.log(res);
if (res == true) {
var alertPopup = $ionicPopup.alert({
title: 'Booking Confirm',
template: 'Thanks For Booking'
});
}
else{
var alertPopup = $ionicPopup.alert({
title: 'Error',
template: ' Not available'
});
}
})
};
我在哪里做错了。我的数据库得到更新,但它总是在下次调用时返回 true。
【问题讨论】:
-
第二次console.log(id, status)和doc的输出是什么
-
console.log(id, status);输出:1 是
标签: javascript angularjs node.js mongodb ionic-framework