How to do post filter with couchnode / couchbase server?

47 views Asked by At

I've been developing using Couchbase Server 4.0 and upgrading to 5.0 is down the road but not at the moment.

But for now I do need to search views (map/reduce) using text search, on Couchbase Lite .Net there is PostFilter that serve the purpose.

But I could not find the same settings on Couchnode, checking the Couchbase Lite .Net told me that a query option might help.

I tried couple of things like this:

  query.options.filter = r => {
    console.log('******', r)
    return true
  }
  query.options.post_filter = r => {
    console.log('******', r)
    return true
  }
  query.options.postFilter = r => {
    console.log('******', r)
    return true
  }

but nothing seems to work. Anyone experienced this before please help!!

1

There are 1 answers

5
Matthew Groves On

On Couchbase server, map/reduce queries are created on the Server cluster itself, not created in the SDK like with Couchbase Lite. An example:

function(doc, meta)
{
  emit(doc.name, [doc.city, doc.salary]);
}

When you create a view, you give it a name. You can call these view from the Node SDK (couchnode) by name like so:

var couchbase = require('couchbase');
var ViewQuery = couchbase.ViewQuery;

var query = ViewQuery.from('beer', 'by_name');

See the documentation: https://docs.couchbase.com/server/4.0/developer-guide/views-writing.html and https://docs.couchbase.com/nodejs-sdk/2.6/view-queries-with-sdk.html