我是Node.js和MongoDB的新手,我真的很想绕过回调。我读了几篇文章,但对我来说仍然很混乱。在下面的代码中,我尝试返回Select Max(mileage)-Min(Mileage) as diff, TruckID
from tableTruck
group by truckid
having count(truckid) > 1
的计数,其中包含我在orders
中的查询中表达的一些属性:
控制器/ order.js:
orderModel.count(query, next)
我认为我没有正确获取变量var mongoose = require ('../config/db');
var orderModel = require('../models/order').model;
var User = require('./user');
var Error = require('../config/error');
createOrder: function (user, order, next) {
if (newOrder.totalPrice > user.credit && orderModel.
count({$and: [{user: order.user}, {active: true}, {$or: [{status: 0}, {status: 1}]}]},
function(err, count){
if(err)
console.log(err);
else
count; }) > 0)
return next({error: Error.InsufficientCredits});
}
,因为当我尝试在count
语句中打印出第二个条件的结果时,我打印出了这些数据:
if