index:
{
last_logged_in: -1, // in milliseconds
age: 1,
city: 1,
}
query:
user.aggregate([
{
$match: {
age: { $gt: 18 },
city: { $in: ["chicago", "paris"] }
}
},
{
$sort: {
last_logged_in: -1
}
},
{
$limit: 10000
}
])
The last_logged_in
field is in milliseconds. So let’s further suppose that all documents hold unique values of this field.
Is this index useful at all in the $match
stage to find the documents?
EDITED:
The better way to phrase this question is, would this index be more effective if the last_logged_in
field is more granular or less granular? For example, milliseconds vs seconds vs hours vs days?