无法运行芒果查询

问题描述 投票:0回答:1

这是我的查询:

{
   "selector": {
      "_id": {
         "$regex": "^rati"  //need to find all documents in ratings partition
      }
   },
   "fields": [
      "MovieID",
      "UserId",
      "Rating"
   ],
   "limit": 10,
   "sort": [
      {
         "MovieID": "asc"
      }
   ]
}

[当我运行此查询时,出现该错误:Error running query. Reason: (no_usable_index) No global index exists for this sort, try indexing by the sort fields.

如果我删除

"sort": [
          {
             "MovieID": "asc"
          }
       ]

一切正常。老实说我快疯了,我不明白我哪里错了。

我已经尝试过此查询:

{
   "selector": {
      "_id": {
         "$regex": "^rati"
      },
      "MovieID": {
         "$gte": 0
      }
   },
   "fields": [
      "_id",
      "MovieID",
      "UserId",
      "Rating"
   ],
   "limit": 10,
   "sort": [
      {
         "_id": "asc"
      }
   ]
}

但相同。

couchdb mangodb couchdb-mango
1个回答
0
投票

MovieID字段必须是选择器的一部分。

在此尝试:

{
   "selector": {
      "_id": {
         "$regex": "^rati"  //need to find all documents in ratings partition
      },
      "MovieID": {"$gte": 0} // include MovieID, If the ID is non-numeric change the selecor type.
   },
   "fields": [
      "MovieID",
      "UserId",
      "Rating"
   ],
   "limit": 10,
   "sort": [
      {
         "MovieID": "asc"
      }
   ]
}

© www.soinside.com 2019 - 2024. All rights reserved.