how to get maximum value in mongoose query . in SQL it is easy
SELECT MAX(LAST_MOD) FROM table1
Where field1=1
i want Equivalent of above SQL code in mongoose(node.js)
See Question&Answers more detail:oshow to get maximum value in mongoose query . in SQL it is easy
SELECT MAX(LAST_MOD) FROM table1
Where field1=1
i want Equivalent of above SQL code in mongoose(node.js)
See Question&Answers more detail:osI couldn't get the other answers to work. Perhaps I'm using a newer version of Mongoose ([email protected]).
This worked for me:
Table1.findOne()
.where({field1: 1})
.sort('-LAST_MOD')
.exec(function(err, doc)
{
var max = doc.LAST_MOD;
// ...
}
);