Feature Request: Console to support View Lookup via key (in addition to document ID)
Is the the right place to post a feature request?
Anyway, I have a map function which emits a key which is composed of two different fields, but to test it I can not put the compound key in the "Lookup Id" field because this only works against document IDs.
It would be great if we can also have a field that allows lookup via the emitted key.
Just to give some backgroud:
We have docuements relating to Invoices. Each invoice is a json document, has a unique id (_id) and sellerID and buyerID fields.
So when we want to find all the invoices issued by seller A against seller B, we use a map funtion with a key made of of sellerA's Id and sellerB's Id. The Invoice document is the value.
Thanks
Adam
Thanks Jan, but...
When I put a value into the "keys" I get:
{"error":"bad_request","reason":"invalid UTF-8 JSON: {{case_clause,<<\"CMP_00239787\">>},\"CMP_00239787\"}"}
URL I have is:
http://192.168.2.71:5984/default/_design/dev_prototype/_view/getAllCompanies?keys=CMP_00239787&connection_timeout=60000&limit=10&skip=0
Just to be clear, I took the key value (CMP_00239787) from the View button without any restriction.
Tried on a few other view methods and same result.
Using the API:
View view = couchbaseClient.getView("prototype", "getAllCompanies");
Query query = new Query();
query.setKey("CMP_00239787");
...and everything works fine.
Thanks Adam
Are you sending the keys as an array? (It expects an array)
Have you tried this: keys = ["CMP_00239787"]
(Remember to have the double quotes)
sveinhelge's correct. It does need to be formatted as an Array.
I've made a ticket for improving the User Experience of that field or (at least) adding a note about how it should be formatted:
http://www.couchbase.org/issues/browse/MB-4277
Feel free to vote for it. :)
Thanks,
Benjamin
OK, so here is the work-around (using the URL)
URL:
http://192.168.2.71:5984/default/_design/dev_prototype/_view/getAllCompanies?keys="CMP_00239787"
Result:
{"error":"bad_request","reason":"`keys` parameter is not an array."}However using:
URL:
http://192.168.2.71:5984/default/_design/dev_prototype/_view/getAllCompanies?key="CMP_00239787"
works fine. Note key rather than keys. And you do have to use the quotes.
Thanks
Adam
I don't see that url as a work-around. If you use the user interface and set keys to ["CMP_00239787"] it will work. (Remember to have the double quotes and square brackets)
Also remember when using the URL http://192.168.2.71:5984/default/_design/dev_prototype/_view/getAllCompanies?key="CMP_00239787" you will only hit that one node running the CouchDB server.Since Couchbase Server 2.0 is a cluster solution that does not make so much sense. The url you are refering to using key="CMP_00239787" is how CouchDB works out of the box.
Just an FYI, there's a commit en route to get "key" added as an option:
http://review.couchbase.org/#change,9524
Thanks, but could you clarify what you mean by only hitting a single node? What URL should be used to hit the full cluster? This URL was taken from the Filter Results link on the View page of Couchebase console.
Thanks
Adam
This URL will get data from one node
http://192.168.2.71:5984/default/_design/dev_prototype/_view/getAllCompanies?key="CMP_00239787"
This URL will get data from the cluster (all nodes holding data for selected bucket)
http://192.168.2.71:5984/default/_design/dev_prototype/_view/getAllCompanies?full_set=true&key="CMP_00239787"
(only difference is the parameter full_set=true)
(If you click the button Full Cluster Data Set an option is added to the URL. full_set=true. When full_set=true is set it will return data from the cluster.)
Now we get data from the cluster, so what is the problem? Well the problem is that you are hitting a specific server even if you get data from the cluster. If you start using that URL in your application it will work as long as the node you are hitting is up and running. If that node fails you will get nothing. Since this is a cluster solution that is not what we normally wants. If you look at the configuration of the different client libraries you will see that they have the possibility to configure several nodes.
This is from the Web.config/App.config (.NET Client Library):
As you see, you can in the server section add all server in the cluster. You can also configure a connection pool++. You may also notice that we are using port 8091. (This is the address to the REST API) Port 5984 is normally blocked for clients. Except for the clients you want to run the web administration tool from.
Read about Moxi (part of Couchbase) for more details.
I not an expert in this area so there are many other people who can more about this and can explain this far better than I can.
Hi Adam,
if you go into the view editor, under run results, there's a triangle that reveals a pop-up box that allows you to specify all sorts of query parameters, including "keys".
For the record, the "official" place to report feature requests is our issue tracker http://www.couchbase.org/issues/ but don't worry too much if you report it here :)
Cheers
Jan
--