How do you do the equivalent of
SELECT
MIN(Id) AS MinId
FROM
Table
with MongoDB?
It looks like I will have to use MapReduce but I can’t find any example that shows how to do this.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use a combination of
sortandlimitto emulatemin:sort({a: 1})is an ascending (minimum-first) sort on theafield, and we then only return the first document, which will be the minimum value for that field.EDIT: note that this is written in the mongo shell, but you can do the same thing from C# or any other language using the appropriate driver methods.