错误:
No index exists for this sort, try indexing by the sort fields.
我尝试在anotherValue
,_id+anotherValue
上创建索引,但没有区别。
这是我的疑问:
{
"selector": {
"_id": { "$gt": null },
"$or": [
{ "_id": "10" },
{ "value": "10", "anotherValue": "1234" }]
},
"sort": [{"anotherValue": "desc"}]
}
索引设置:
Your available Indexes:
special: _id
答案 0 :(得分:1)
尝试在anotherValue上添加desc索引:
{
"index": {
"fields": [
{"anotherValue":"desc"}
]
},
"type": "json"
}
并将您的查询更改为:
{
"selector": {
"anotherValue": { "$gt": null },
"$or": [
{ "_id": "10" },
{ "value": "10", "anotherValue": "1234" }
]
},
"sort": [{"anotherValue": "desc"}]
}
注意:如果您在所有字段上添加了文本索引,原始查询也会起作用:
{
"index": {},
"type": "text"
}