The Last Document Revison on N1QL is possible?

121 views
Skip to first unread message

Alan Diaz

unread,
Feb 8, 2016, 6:25:13 PM2/8/16
to Couchbase Mobile


hi, i have a question in a project i want to get the last revision of a documento via N1QL but i don't know if this is possible.

someone can help?

P.D. if someone think on say "by this exist the SDK methods" i know, but i want to save time and work

Jens Alfke

unread,
Feb 8, 2016, 6:44:18 PM2/8/16
to mobile-c...@googlegroups.com

On Feb 8, 2016, at 2:59 PM, Alan Diaz <alan...@gmail.com> wrote:

hi, i have a question in a project i want to get the last revision of a documento via N1QL but i don't know if this is possible.

You can query SG’s bucket via N1QL, as long as you
  • ignore keys (doc IDs) that start with “sync:” — these are internal data, not real documents
  • ignore the “_sync” property of a document, which contains internal metadata
  • do NOT make any changes
The remainder of the document is the current revision.

—Jens

Sandra Bazan

unread,
Feb 8, 2016, 9:27:56 PM2/8/16
to Couchbase Mobile
Hello Jens, 
    How do we tell N1QL to ignore keys that start with "sync" so that we actually retrieve the last revision of each document? 
    Does it matter if at document creation, we are assigning specific key to each document instead of allowing CB to assign a default key (name)? We don't wee any document starting with "sync".
We appreciate any help,
Sandra

Jens Alfke

unread,
Feb 9, 2016, 12:02:26 AM2/9/16
to mobile-c...@googlegroups.com
On Feb 8, 2016, at 6:27 PM, Sandra Bazan <sba...@txmglobal.com> wrote:

    How do we tell N1QL to ignore keys that start with "sync" so that we actually retrieve the last revision of each document? 

I don’t actually know N1QL. You may have better luck asking in the Couchbase Server web forums.

    Does it matter if at document creation, we are assigning specific key to each document instead of allowing CB to assign a default key (name)? We don't wee any document starting with "sync".

No, it doesn’t matter.

—Jens

Victor Fernandez

unread,
Feb 10, 2016, 11:07:49 AM2/10/16
to Couchbase Mobile
Ok we add an aditional restriction to the query like the example:
SELECT * FROM holamundo WHERE META(holamundo).id NOT LIKE "%sync%" AND tableId="L1";

And it looks like works! Thanks for your advice

Regards!

Jens Alfke

unread,
Feb 10, 2016, 11:53:36 AM2/10/16
to mobile-c...@googlegroups.com
Use "sync:%", not "%sync%". You only want to block IDs that start with "sync:".

—Jens 
--
You received this message because you are subscribed to the Google Groups "Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mobile-couchba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mobile-couchbase/9abff64c-7660-4f60-9142-88da7474ad19%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages