无法 运行 Mango 查询
Unable to run a Mango query
这是我的查询:
{
"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"
}
]
}
但是是一样的。
您需要为字段创建索引MovieID
//Create via POST /db/_index HTTP/1.1 Content-Type: application/json
{
"index": {
"fields": ["MovieID"]
},
"name" : "MovieID-index",
"type" : "json"
}
然后将字段 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"
}
]
}
这是我的查询:
{
"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"
}
]
}
但是是一样的。
您需要为字段创建索引MovieID
//Create via POST /db/_index HTTP/1.1 Content-Type: application/json
{
"index": {
"fields": ["MovieID"]
},
"name" : "MovieID-index",
"type" : "json"
}
然后将字段 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"
}
]
}