如何在 Mongoose 查询中获取最大值。在 SQL 中很容易
SELECT MAX(LAST_MOD) FROM table1
Where field1=1
我想在 mongoose(node.js) 中等效于上述 SQL 代码
最佳答案
我无法得到其他答案。也许我正在使用更新版本的 Mongoose (mongoose@3.0.1)。
这对我有用:
Table1.findOne()
.where({field1: 1})
.sort('-LAST_MOD')
.exec(function(err, doc)
{
var max = doc.LAST_MOD;
// ...
}
);
关于node.js - 在 Mongoose 中获得最大值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10572592/