我在MEAN STACK应用程序工作。
我不能使猫鼬查询猫鼬像MYSQL查询下面给出
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。
你可以试试:
user.find({_id : id}).sort({_id : 1}).exec(function(err,result){...});
如果User
为Mongoose Schema,则:
User
.find({_id : {$in: [11, 12, 14]}})
.sort({_id : 1})
.exec(function(err,result){
});