mongoose \ mongodb按某种列表排序?

时间:2016-08-15 05:20:29

标签: node.js mongodb mongoose mean-stack database

我在MEAN STACK应用程序中工作 我不能像在MYSQL查询中那样在mongoose中进行mongoose查询,如下所示

SELECT _id, username
FROM user
ORDER BY FIELD(_id, "575123d687ed49be12404584", "575123d687ed49be12404587", "572d8b5aab1db7e1160a273a", "575123d687ed49be124045a5")

从此我想使用mongoose

按照以下顺序排出
first document (record) -> 575123d687ed49be12404584  
second document (record) -> 575123d687ed49be12404587  
third document (record) -> 572d8b5aab1db7e1160a273a  
fourth document (record) -> 575123d687ed49be124045a5  
remaining are in ascending order.

任何人都可以给我一个合适的解决方案,让结果给予ORDER BY。

1 个答案:

答案 0 :(得分:0)

你可以试试这个:

user.find({_id : id}).sort({_id : 1}).exec(function(err,result){...});