Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我无法使用 mongo 按降序排序。
示例:我有多个带有字段分数的条目。
{_id:1, score:0} {_id:2, score:1} {_id:3, score:-1}
当我运行以下命令时
db.entries.find({}).sort({score:-1});
它按以下顺序排列:
{_id:2, score:1} {_id:3, score:-1} {_id:1, score:0}
知道为什么会这样,有什么解决办法吗?
尝试这个
db.entries.find().sort({score:-1})
代替
db.entries.find({}).sort({score:-1})
没关系,我发现了这个错误,我将分数存储为字符串,这导致了错误。