在模型的远程方法中使用查找时,回送顺序过滤器错误:

gro*_*roo 1 sorting loopback node.js loopbackjs

我在使用远程方法的查找中使用简单的排序过滤器时遇到了麻烦:

    /**
 * 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'}}
  ]
});
Run Code Online (Sandbox Code Playgroud)

在上方,您可以看到我的remote / find实现,它在没有订单过滤器的情况下也可以正常运行。

订单{“ mealDate”:“ DESC”}无效

mealDate是我模型上的Date类型。

"properties": {
"mealDate": {
  "type": "date",
  "required": true,
  "default": "Date.now"
},
Run Code Online (Sandbox Code Playgroud)

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

PS-我知道我可以在数组中使用直接排序来做到这一点,但是在这种情况下,我尝试使用回送过滤器。

Yoh*_*tom 5

基于文档,我认为应该是这样的:

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