Couchbase wildcards / variable keys

After some research and testing with Couchbase, I am getting good results. However, it seems odd that views have to be created by a head of time and are not very flexible.

Basically, if I have such an idea.

function(doc, meta) {
    emit([doc.name, doc.location, doc.gender, doc.birthYear, doc.birthMonth], null);
}

      

And I only want to request different keys. For example, maybe name = "John" and gender = "M" I can't seem to do startKey = ["John", {}, "M"], endKey = ["John", {}, "M", {}].

Likewise, what if I just want to filter higher by gender and birth month? I seem to have to manually sort the individual view for every possible query type, which is with a lot of data points, if less optimal.

I haven't seen any questions regarding this. Also, I looked into fleeting arguments to map or scale down to make any of them dynamically, but it can't be done. I would be stuck pulling out ALL records at all levels of the group and then manually sorting / collecting that data.

Can this be done?

thank

+3


source to share


2 answers


As of Couchbase 4.x, you are N1QL Query Language . You can specify filter criteria to select json objects without any views.

So, according to your example, you should be able to issue a request like this:

SELECT *
  FROM your_bucket_name
    WHERE name = 'John' AND gender = 'M'

      



Here's a N1QL tutorial to get a feel for it.

Another way is to use the Couchbase integration with ElasticSearch and do a search query in the ElasticSearch engine that will return you all the keys found based on your search criteria.

+2


source


http://www.couchbase.com/communities/n1ql



N1QL is a richer language for communicating couchbase data that is not limited to presentation

+1


source







All Articles