0
votes

Using the Loopback API explorer GET try this button with and without a filter, I am getting result no_usable_index:

{ "error": { "statusCode": 400, "name": "Error", "message": "No index exists for this sort, try indexing by the sort fields.", "error": "no_usable_index", "reason": "No index exists for this sort, try indexing by the sort fields.", "scope": "couch", "request": { "method": "post", "headers": { "content-type": "application/json", "accept": "application/json" }, "uri": "https://XXXXXX:[email protected]/aac_001_dev_db/_find", "body": "{\"selector\":{\"loopback__model__name\":\"Center\"},\"use_index\":[\"lb-index-ddoc-Center\",\"lb-index-Center\"],\"sort\":[{\"id:string\":\"asc\"}]}" }, "headers": { "x-frame-options": "DENY", "x-couch-request-id": "658ac2fdf8", "date": "Tue, 06 Mar 2018 17:45:29 GMT", "content-type": "application/json", "cache-control": "must-revalidate", "strict-transport-security": "max-age=31536000", "x-content-type-options": "nosniff", "x-cloudant-request-class": "query", "x-cloudant-backend": "bm-cc-us-south-02", "via": "1.1 lb1.bm-cc-us-south-02 (Glum/1.50.1)", "statusCode": 400, "uri": "https://XXXXXX:[email protected]/aac_001_dev_db/_find" }, "errid": "non_200", "description": "couch returned 400", "stack": "Error: No index exists for this sort, try indexing by the sort fields.\n at Request._callback (/home/ubuntu/workspace/aac-001-api/node_modules/loopback-connector-cloudant/node_modules/cloudant/node_modules/cloudant-nano/lib/nano.js:248:15)\n at Request.self.callback (/home/ubuntu/workspace/aac-001-api/node_modules/loopback-connector-cloudant/node_modules/cloudant/node_modules/request/request.js:186:22)\n at emitTwo (events.js:106:13)\n at Request.emit (events.js:191:7)\n at Request.<anonymous> (/home/ubuntu/workspace/aac-001-api/node_modules/loopback-connector-cloudant/node_modules/cloudant/node_modules/request/request.js:1163:10)\n at emitOne (events.js:96:13)\n at Request.emit (events.js:188:7)\n at IncomingMessage.<anonymous> (/home/ubuntu/workspace/aac-001-api/node_modules/loopback-connector-cloudant/node_modules/cloudant/node_modules/request/request.js:1085:12)\n at IncomingMessage.g (events.js:292:16)\n at emitNone (events.js:91:20)\n at IncomingMessage.emit (events.js:185:7)\n at endReadableNT (_stream_readable.js:974:12)\n at _combinedTickCallback (internal/process/next_tick.js:80:11)\n at process._tickCallback (internal/process/next_tick.js:104:9)" } }

So I tried searching the lb3 documentation and found a cloudant-connector loopback.io / doc / en / lb3 / Cloudant-connector.html#index that describes the index feature as "To be updated". Hmmm, it is listed as a feature backlog.

Then I found [:link:][2] to the Model-definition-JSON-file which describes manually adding an indexes property. I tried:

  // common -> models -> center.json
  "indexes": {
      "name_index": {"name": 1}
  }, ...

I also tried the suggestion: "You can specify indexes at the model property level too, for example:"

  "properties": {
    "name": {
      "type": "string",
      "required": true,
      "index": true   // added this (but without the comment :)
    }, ...

Alas, none of these attempts worked. I am still getting the error.

I have watched several off topic youtube videos of Loopback with MongoDB, but it is curious that there is not much available showing exactly how to get the Loopback-connector to work with Cloudant.

At this point I just want:

  1. to GET the two test documents that have been POSTed using the the API explorer.
  2. to know if these cloudant-connector GET methods work at all with lb version 3.

I added a mongodb datasource from the command line and edited the model-config.json file datsource parameter to point to the mongodb database, then performed a similar test. Added two documents with the POST button, then clicked try this with the GET button. It returns the two documents that were posted, just like in the youtube video tutorials.


Update with more clues

  1. In the Cloudant dashboard query page there is a selector. If I make an errant change to the selector, Cloudant returns the error "no_usable_index". This means that the error message is not from Loopback, it is from Cloudant, but passed through Loopback.

  2. Although the Loopback explorer has the same visual look and feel for both the mongo-connector and cloudant-connector; the url (REST) interface to the databases clearly must be different. I assumed that the POST, GET sequence of button clicks in the explorer that works to connect with Mongodb would work with Cloudant. It does not. Cloudant requires that a design document be available in the database to define valid queries.


I know for sure the database is accessible from the command line with:

$ curl $CLOUDANT_URL/$CLOUDANT_DATABASE

and with a design doc defined within the database

$ curl $CLOUDANT_URL/$CLOUDANT_DATABASE/_design/$DDOC_MEDICAL_CENTERS/_view/$VIEW_MEDICAL_CENTERS_TRUE

1
What's your query look like?A. J. Alger

1 Answers

0
votes

After much troubleshooting in the old version I found that the error went away when I changed

FROM [email protected] 3-Aug 2017

TO [email protected] 23-Mar 2018

by updating the package.json and running an npm update