I am using loopback-connector-cloudant and I am able to connect to the IBM bluemix cloudant service by using the credentials.
I am able to post json data record into the created database in the cloudant by using the loopback API explorer POST method for the model.
However when I tried to use loopback API explorer GET to read the posted data from the cloudant database, I got the "no_usable_index" error.
{
"error": {
"name": "Error",
"status": 400,
"message": "No index matches the index specified with \"use_index\"",
"error": "no_usable_index",
"reason": "No index matches the index specified with \"use_index\"",
"scope": "couch",
"statusCode": 400,
"request": {
"method": "post",
"headers": {
"content-type": "application/json",
"accept": "application/json"
},
"uri": "https://XXXXXX:XXXXXX@c381c9d9-7502-4bff-ae2f-69f7ba646ade-bluemix.cloudant.com/camera/_find",
"body": "{\"selector\":{\"loopback__model__name\":\"Camera\"},\"use_index\":[\"lb-index-ddoc-Camera\",\"lb-index-Camera\"]}"
},
"headers": {
"x-couch-request-id": "d2d09498da",
"date": "Thu, 07 Jan 2016 02:06:47 GMT",
"content-type": "application/json",
"cache-control": "must-revalidate",
"strict-transport-security": "max-age=31536000",
"x-content-type-options": "nosniff;",
"connection": "close",
"statusCode": 400,
"uri": "https://XXXXXX:XXXXXX@c381c9d9-7502-4bff-ae2f-69f7ba646ade-bluemix.cloudant.com/camera/_find"
},
"errid": "non_200",
"description": "couch returned 400",
"stack": "Error: No index matches the index specified with \"use_index\"\n at Request._callback (/home/vcap/app/node_modules/loopback-connector-cloudant/node_modules/cloudant/node_modules/nano/lib/nano.js:248:15)\n at Request.self.callback (/home/vcap/app/node_modules/loopback-connector-cloudant/node_modules/cloudant/node_modules/nano/node_modules/request/request.js:198:22)\n at Request.emit (events.js:110:17)\n at Request.<anonymous> (/home/vcap/app/node_modules/loopback-connector-cloudant/node_modules/cloudant/node_modules/nano/node_modules/request/request.js:1082:10)\n at Request.emit (events.js:129:20)\n at IncomingMessage.<anonymous> (/home/vcap/app/node_modules/loopback-connector-cloudant/node_modules/cloudant/node_modules/nano/node_modules/request/request.js:1009:12)\n at Object.forward (/home/vcap/app/node_modules/strong-start/node_modules/strong-pm/node_modules/strong-runner/node_modules/strong-supervisor/node_modules/strong-agent/lib/proxy.js:79:23)\n at IncomingMessage.eval (eval at wrap (/home/vcap/app/node_modules/strong-start/node_modules/strong-pm/node_modules/strong-runner/node_modules/strong-supervisor/node_modules/strong-agent/lib/proxy.js:201:20), <anonymous>:3:21)\n at IncomingMessage.emit (events.js:129:20)"
}
}
I can see that the loopback is trying to use index of lb-index-ddoc-Camera and lb-index-Camera but couldn't find the matches index in the database.
What should I do? Should I create such index with the same name as lb-index-ddoc-Camera and lb-index-Camera? Where are these index come from?
Anyone have been successfully used the loopback-connector-cloudant?
In the meantime I will try to use loopback-connector-couch instead.
Answer by amilab (81) | Jan 06, 2016 at 09:16 PM
I solved the issue.
The reason my GET method is not working for loopback is that the index is not build when using the loopback-connector-cloudant due to wrong configuration format in the datasource.json file.
I used the below format and it works.
"mydb": {
"name": "mydb",
"connector": "cloudant",
"username": "XXXX-bluemix",
"password": "YYYYYYYYYYYY",
"database": "test"
}
Answer by Ryan Cox (95) | Sep 30, 2016 at 03:48 PM
Can you explain what you changed in the datasource.json that made this work? I'm having the same issue and it looks like you only removed the "modelIndex" attribute. I've removed this attribute as well and still get the same "No index matches the index specified with \"use_index\"" error.
Answer by Sebastián Vergara (1) | May 01, 2017 at 07:17 PM
I removed the url property, added the username and password and started working.
Answer by Henrik_Warfvinge (1) | Jan 09, 2018 at 07:31 AM
Hi, you must have done something different then just this no ? I have this problem now. First time I get it and it should work. Will look more for answers but any more thoughts around this ?? Thanks!
Answer by Henrik_Warfvinge (1) | Jan 09, 2018 at 07:55 AM
Okey, so should not have anything to do with the URL to cloudant. My misstake was to now have created a GET service in my node.js loopback app - which in turn made my request fail. It works even with the URL included in the datascource.json file. Cheers
Answer by NorthDecoder (3) | Feb 28, 2018 at 10:22 AM
Just using the Loopback API explorer GET try this button I am getting a very similar result:
{
"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", ...
So I tried searching the lb3 documentation and found a cloudant-connector :link: that describes the index feature as "To be updated". Hmmm, it is listed as a feature backlog.
Then I found :link: 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 this worked. I am still getting the error.
I have watched several 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.
After much troubleshooting in the old version I found that the error went away when I changed
FROM loopback-connector-cloudant@1.2.5
3-Aug 2017
TO loopback-connector-cloudant@2.0.5
23-Mar 2018
by updating the package.json and running an npm update