Loopback order filter when using find in a remote method from a model, error:

Loopback order filter when using find in a remote method from a model, error:

我在远程方法的查找中使用简单的排序过滤器遇到困难:

    /**
 * This remote method exposes the meals history from the current logged in user
 */
Meal.listMeals = function(req, res, cb) {
  Meal.find({
    where: {patientId: req.accessToken.userId},
    order: {mealDate: 'DESC'}
  }, cb);
};
Meal.remoteMethod('listMeals', {
  returns: {arg: 'meals', type: 'array'},
  http: {path:'/list-meals', verb: 'get'},
  accepts: [
    {arg: 'req', type: 'object', http: {source: 'req'}},
    {arg: 'res', type: 'object', http: {source: 'res'}}
  ]
});

上面你看到我的远程/查找实现,它在没有订单过滤器的情况下正常工作..一旦我添加那个 oder {mealDate: 'DESC'} 我得到一个错误:

The order {"mealDate":"DESC"} is not valid

mealDate 是我模型上的日期类型。

"properties": {
"mealDate": {
  "type": "date",
  "required": true,
  "default": "Date.now"
},

任何想法可能是什么问题?我已经坚持了一段时间,我想解决方案很简单..

P.S - 我知道我可以在数组中直接使用排序来执行此操作,但我在这种情况下尝试使用环回过滤器。

根据doc,我觉得应该是这样的:

Meal.find({
  where: {patientId: req.accessToken.userId},
  order: 'mealDate DESC' 
}, cb);

环回 4 :

Meal.find({
  where: {patientId: req.accessToken.userId},
  order: ['mealDate DESC'],
});