Suppose I have the following documents:
{
"name":"Matheus",
"age: 29"
},
{
"name":"Nicolas",
"age: 28"
},
{
"name":"Raphael",
"age: 26"
},
{
"name":"Trump",
"age: 48"
},
{
"name":"Elon Musk",
"age: 35"
}
Now, suppose I want to retrieve the document with the greatest age, but up to a given age, like this: return document with the greatest age up to 36, this should return
"name":"Elon Musk",
"age: 35"
}
Note that the less or equal operator wouldn't work, because I don't need the greatest of all, I need the greatest up to a certain number. I've learned here that I can acomplish almost what I want by doing
db.collection.find().sort({age:-1}).limit(1) // for MAX
but I don't need the global max, just the max inside a given bound. How can I acomplish this?