【发布时间】:2016-03-17 06:24:28
【问题描述】:
我有来自anotherCollection.. 的 id 数组。经过多次计算,我得到:
idSortByRank = ["cxwMoC3k6kpf4mr5o","HFYjC5nuT9hKhdyFC","GiM7NCLjck6Pet8Wm"]
我需要从 MyCollection 的 mongodb 集合中返回对象,该集合由 idSortByRank 排序/索引,如下所示:
//expected result should index/sort the same as idSortByRank
[
{"_id": "cxwMoC3k6kpf4mr5o", other field},
{"_id": "HFYjC5nuT9hKhdyFC", other field},
{"_id": "GiM7NCLjck6Pet8Wm", other field}
]
我这样做了,但没有按预期排序:
MyCollection.find({_id:{$in:idSortByRank}});
我在MyCollection 中没有rank 字段
非常感谢...
【问题讨论】:
-
你不能这样做是 Mongodb 查询。从 DB 获得结果后,您需要手动执行此操作。
-
您能解释一下您希望它们如何排序吗?
标签: javascript arrays mongodb sorting underscore.js