在猫鼬中获得最大值 [英] get max value in mongoose
本文介绍了在猫鼬中获得最大值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在 mongoose 查询中获取最大值.在 SQL 中很容易
how to get maximum value in mongoose query . in SQL it is easy
SELECT MAX(LAST_MOD) FROM table1
Where field1=1
我想要 mongoose(node.js) 中的上述 SQL 代码的等价物
i want Equivalent of above SQL code in mongoose(node.js)
推荐答案
MongoDB 支持 max/min,但他们不建议在实际应用中使用它:
MongoDB supports max/min, but they don't recommend using it in real applications :
min 和 max 的存在主要是为了支持 mongos(分片)过程.
min and max exist primarily to support the mongos (sharding) process.
http://www.mongodb.org/display/DOCS/min+and+max+Query+Specifiers
你可以得到几乎相同的结果:
You could pretty much have the same result with :
Model.findOne({ field1 : 1 }).sort(last_mod, 1).run( function(err, doc) {
var max = doc.last_mod;
});
这篇关于在猫鼬中获得最大值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文