4

我不确定如何使用 Mango 查询对文档进行排序。任何帮助将不胜感激:


我执行以下查找查询并收到以下错误:

return db.find({ sort: ['timestamp'], selector: {$and: [{type:"revision"},{doc_id: doc_id}] } })

请注意,如果我执行以下操作,我也会收到相同的错误:

return db.find({ sort: ['timestamp'], selector: {$and: [{type:"revision"}] } })

{ 错误:'no_usable_index',原因:'此排序不存在索引,尝试按排序字段索引。',名称:'no_usable_index',状态:400,消息:'此排序不存在索引,尝试按排序字段。}

我创建了一个像这样的过滤器:

db.createIndex({
  index: {fields: ['type', 'timestamp']}
})

这是我的设计文档中弹出的内容:

{
  "_id": "_design/b661014513bf0c13270a9033d6d1c1853a8b5dbf",
  "_rev": "1-1d871456b0a78952845705f4e8dd2c26",
  "language": "query",
  "views": {
    "b661014513bf0c13270a9033d6d1c1853a8b5dbf": {
      "map": {
        "fields": {
          "type": "asc",
          "timestamp": "asc"
        },
        "partial_filter_selector": {}
      },
      "reduce": "_count",
      "options": {
        "def": {
          "fields": [
            "type",
            "timestamp"
          ]
        }
      }
    }
  }
}
4

0 回答 0