在sailsjs查询中禁用排序

时间:2016-05-04 12:17:17

标签: javascript mongodb sails.js

我有一些id存储在数组locationIds中,它已经按照我想要的方式排序。但是使用以下代码,我将以风帆默认排序顺序获得响应。

var locationIds = []; // pushing id's in it
Locations.find({ id: locationIds }).paginate({ page: page, limit: limit }).exec(function(err, sortedLocations) {
  // need the response in the same order as in locationIds
});

有什么方法可以禁用此默认排序或任何其他可能性?需要帮助,提前感谢。

1 个答案:

答案 0 :(得分:0)

正如评论中所提到的,如果您没有指定排序顺序,则无法保证结果会以什么顺序进入。如果您有特定的订单,则该订单独立于任何在现有字段中,最好的方法是在记录中添加order字段,您可以使用这些字段手动排序,然后对其进行排序。