Unable to run a Mango query

Unable to run a Mango query

Questions : Unable to run a Mango query

115

This is my query:

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

When I run this query I have that error: in4codes_couchdb Error running query. Reason: in4codes_couchdb (no_usable_index) No global index exists for in4codes_couchdb this sort, try indexing by the sort fields.

If I remove

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

everything works good. Honestly I’m going in4codes_couchdb crazy, I can’t understand where I’m wrong.

I’ve tried this query:

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

but is the same.

Total Answers 1
26

Answers 1 : of Unable to run a Mango query

You need to create an Index for the in4codes_couchdb-mango field MovieID

//Create via POST /db/_index HTTP/1.1 Content-Type: application/json { "index": { "fields": ["MovieID"] }, "name" : "MovieID-index", "type" : "json" } 

Afterward include the field MovieID as in4codes_couchdb-mango part of the Selector.

Try this here:

{ "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" } ] } 

0