0

我正在为 MongoDB 创建分步请求。一切正常,但 Mongo 无法识别排序选项。我做错了什么?

var request = {}
    request['show'] = 1;
    request['category'] = category;
    switch (sort) {
        case "new_first":
            request['sort'] = "[['time_added', -1]]";
            break;
        case "old_first":
            request['sort'] = "[['time_added', 1]]";
            break;
    }
collection.find(request, function(err, posts) {
....    

谢谢!

4

1 回答 1

0

找到了解决方案:

sort_query = JSON.parse('{"sort":[["time_added",-1]]}')

有效!

于 2012-09-22T20:53:04.940 回答