对非主索引的字段执行排序

Perform sort on field that's not primary index

错误:

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

尝试在另一个值上添加 desc 索引:

{
  "index": {
    "fields": [
      {"anotherValue":"desc"}
    ]
  },
  "type": "json"
}

并将您的查询更改为:

{
  "selector": {
    "anotherValue": { "$gt": null },
    "$or": [
      { "_id": "10" },
      { "value": "10", "anotherValue": "1234" }
    ]
  },
  "sort": [{"anotherValue": "desc"}]
}

注意:如果您在所有字段上添加文本索引,您的原始查询也将有效:

{
  "index": {},
  "type": "text"
}