N1QL query returns all version

132 views
Skip to first unread message

Victor Fernandez

unread,
Sep 29, 2014, 6:23:52 PM9/29/14
to couc...@googlegroups.com
Hi I have the N1QL process running in my couchbase server, I'm making REST petitions to make the querys but the problem is that te query returns all the versions of a document. I only need the latest version, is there a way to do this?

Gerald

unread,
Sep 30, 2014, 10:28:26 AM9/30/14
to couc...@googlegroups.com
Hi,

If you have a version field, you can do something like:

select *
from my-bucket
where ...
order by version desc
limit 1

Victor Fernandez

unread,
Sep 30, 2014, 10:30:30 AM9/30/14
to couc...@googlegroups.com
Hi Gerald, this version field is from Metadata? or  your suggestion is to add a field for versions?

Gerald Sangudi

unread,
Sep 30, 2014, 10:38:49 AM9/30/14
to couc...@googlegroups.com
Hi Victor,

How is it that you are getting multiple versions? What versions were you referring to in your original posting?

Also, how do you know that it is multiple versions of the same document, as opposed to separate documents?

--
You received this message because you are subscribed to a topic in the Google Groups "Couchbase" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/couchbase/uivm95SLkFE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to couchbase+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Victor Fernandez

unread,
Sep 30, 2014, 10:51:16 AM9/30/14
to couc...@googlegroups.com
Yes Gerald for example I have a document named user::vfernandez. This doc have two fields age and name, if I modify this document through the sync gateway another version of the same document it's created. When I do the select with NIQL, this process returns me the first version of the document (when it was created) and the second version (after this was modified). I only need the last revision

Matt Ingenthron

unread,
Sep 30, 2014, 1:34:03 PM9/30/14
to couc...@googlegroups.com
Hi Victor,

You should not be directly querying the bucket used by sync gateway.  The intent, at the moment, is that you use the bucket shadowing functionality there to shadow it to another bucket, and then you can query from there with N1QL.

Then you’ll have only one version, as determined by SyncGateway, in the shadow.

Thanks,

Matt

You received this message because you are subscribed to the Google Groups "Couchbase" group.
To unsubscribe from this group and stop receiving emails from it, send an email to couchbase+...@googlegroups.com.

Victor Fernandez

unread,
Apr 1, 2015, 2:34:33 PM4/1/15
to couc...@googlegroups.com
Hi Matt
Do you know if there is possible to querying directly to the bucket used by the sync gateway in this new version of N1QL (DP4)? 
Because, I have some synchronizing issues between this bucket and the shadow bucket, after several time I got discrepancies

Pradip Vaghasiya

unread,
Jan 7, 2016, 1:43:08 PM1/7/16
to Couchbase
Hi Victor, Did you get the answer of whether N1QL query on sync gateway bucket is allowed?

Sandra Bazan

unread,
Feb 8, 2016, 9:34:24 PM2/8/16
to Couchbase
Hello Pradip, I work with Victor, and no, we have not received any answer  :(   the only solution we know to this issue is to use shadow bucket, we thought that with the usage of the new SDK we would be able to get rid of the shadow bucket. But unfortunately, it seems this won't be possilble.

Sandra

Matt Ingenthron

unread,
Feb 10, 2016, 2:27:28 AM2/10/16
to Couchbase
My apologies for missing the update on the thread here.  For what it's worth, most of the community discussion has moved to forums.couchbase.com.

Recently Jens from the mobile team answered this question in another group.  The answer is yes with some additional details you can see in that posting.

Shadow buckets are discouraged at this point.  

The team is definitely looking to make this simpler in the future.
Reply all
Reply to author
Forward
0 new messages