N1ql + sync gateway


#1

Hi All,

I’m planning to use couchbase server 5.5 together with sync gateway 2.1. We’re currently using cb 4.6 and sg 1.3 and fetching data using sync gateway views and channeling system.

On web side, is there a way to use n1ql using user’s session?

I’m planing to use n1ql array_intersect(channels, userChannels), what is the best practice for this?


I want to retreive the current rev value of my objects via N1QL
#2

Starting 5.5, we have N1QL query that will allow you to access the sync metadata associated with a SGW processed document …

select meta().xattrs._sync fromtravel-samplewhere meta().id ="mydocId”

So once you get the raw sync metadata, you would have to process it.

But there isn’t a query that will allow you directly query for channels or other metadata in an opaque manner - the way you probably want it. It is something we are considering for the future.To that end, can you provide a little more insight into your use case.


#3

So the most efficient way to get the documents that includes sync gateway user’s channel is to include it on the query like this?:

var user_channels = [“CUSTOMER”, “PRODUCT”, “ORDER”]

SELECT *
FROM default
WHERE type == “CUSTOMER”
AND ARRAY_LENGTH(ARRAY_INTERSECT(document_channels, user_channels)) > 1;