2016-04-26 6 views
0

Fehler nicht Primärindex ist:Führen Art auf dem Feld, die

No index exists for this sort, try indexing by the sort fields. 

Ich habe versucht, Indizes auf anotherValue, _id+anotherValue, aber keinen Unterschied zu schaffen.

Dies ist meine Frage:

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

Indizes Setup:

Your available Indexes: 
special: _id 

Antwort

1

Versuchen Sie, einen desc Index auf another Zugabe:

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

und Ihre Abfrage dies ändern:

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

Hinweis: Ihre ursprüngliche Abfrage würde auch funktionieren, wenn Sie einen Textindex für alle Felder hinzugefügt:

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

Dank! versuchen zu vermeiden '{" index ": {}," type ":" text "}' weil off Perf Implikationen – bobbyrne01

Verwandte Themen