Reputation: 21
I am trying to create a view in couchbase. Below is my query,
function (doc, meta) {
if (doc._class == "com.abc.xyz.Account" && doc.accountId) {
emit(doc.accountId, null);
}
}
However, I am getting below exception:
{"error":"Error, you cannot issue more than one query at once. Please remove all text after the semicolon closing the first query."}
Not sure what is the issue with the query. Tried searching for the solution but couldn't find any.
Upvotes: 0
Views: 338
Reputation: 96
The javascript function mentioned in the question appears to be a Couchbase Map/Reduce View Engine definition. These can be queried using either SDK or REST API, and details are outlined in View Querying section. In addition, the Map/Reduce View UI (same place where the map/reduce functions are defined) has some limited capability to query the view being defined.
The Couchbase Query UI is exclusively for N1QL/SQL++ queries. The function mentioned can be expressed in N1QL very easily:
CREATE INDEX ON mybucket(accountId) WHERE _class == "com.abc.xyz.Account";
So it would not be necessary to create Couchbase Map/Reduce views. And the above index can be queried, for example, as:
SELECT count(*) FROM mybucket WHERE _class == "com.abc.xyz.Account";
I'm sure the above function you mention is just an example, and the actual use case is more complex, but the general approach still holds true. It's a good idea to start by using declarative tool (N1QL) as it is much simpler to use.
There are many useful resources for this such as the N1QL Tutorial to help start using N1QL. This would be the best starting point for most use cases.
Upvotes: 2