get max value in mongoose

后端 未结 5 1702
心在旅途
心在旅途 2020-12-20 15:23

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

5条回答
  •  被撕碎了的回忆
    2020-12-20 15:36

    I couldn't get the other answers to work. Perhaps I'm using a newer version of Mongoose (mongoose@3.0.1).

    This worked for me:

    Table1.findOne()
        .where({field1: 1})
        .sort('-LAST_MOD')
        .exec(function(err, doc)
        {
            var max = doc.LAST_MOD;
            // ...
        }
    );
    

提交回复
热议问题