此文档结构的最佳索引顺序是什么?
find:
{
"location": {
"$geoWithin": {
"$centerSphere": [
["<val>"], "<val>"
]
}
},
"isDeleted": "<val>",
"updatedAt": {
"$lte": "<val>",
"$gte": "<val>"
},
"_userId": {
"$nin": ["<vals>"]
}
}
sort:
{
"updatedAt": -1
}
我的假设是:
{
"isDeleted": 1, // Boolean first because it rules out big chunks of the data set
"updatedAt": -1, // Rule: place sort fields before range fields
"location": "2dsphere",
"_userId": 1
}
但是我不确定索引中location
的顺序。
最好的顺序是什么?为什么?