【发布时间】:2016-05-04 12:17:17
【问题描述】:
我有一些 id 存储在数组 locationIds 中,它已经按照我想要的方式排序。但是使用下面的代码,我得到了sails默认排序顺序的响应。
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
});
有什么方法可以禁用此默认排序或任何其他可能性?需要帮助,提前致谢。
【问题讨论】:
-
当您没有在 MongoDB 中指定任何顺序时,您无法保证您将获得记录的顺序。您应该按自然顺序获得它,但您不能 100% 确定。见How does MongoDB sort records when no sort order is specified?
-
好吧,除了禁用它,还有其他方法可以解决这个问题吗?
标签: javascript mongodb sails.js