SG View sorting

43 views
Skip to first unread message

Todd Freese

unread,
Aug 3, 2015, 6:06:26 PM8/3/15
to Couchbase Mobile
I am having troubles getting sorted results from a sync gateway view.

Here is my map function:

{
    "views":{
        "scenes_for_job":{
            "map":"function (doc, meta) { if (doc.type == \"scene\") { emit([doc.job_id, doc.sceneNumber], doc); } }"
        }
    }
}

And here is my REST call:


My data returning from this has the same doc.job_id for all docs and different doc.sceneNumber for each doc. I would like an ascending sort on sceneNumber.

What am I missing here?

Also, I am only returning the entire doc for debugging purposes, I will remove that later on down the line.

Todd

Jens Alfke

unread,
Aug 3, 2015, 6:59:49 PM8/3/15
to mobile-c...@googlegroups.com
It would be better to use {} as a placeholder instead of “\uefff”. I don’t think it makes a difference in this case, but {} is the usual idiom for “something larger than any possible key”. The huge-Unicode-character is sort of a kludge that’s appended to a string to get a prefix match.

My data returning from this has the same doc.job_id for all docs and different doc.sceneNumber for each doc. I would like an ascending sort on sceneNumber.

It should be returning rows for all docs where the job_id is ≤ “FEB04…”.
What order do the scene numbers actually appear in? (And did you make sure that sceneNumber is a number not a string?)

—Jens

Todd Freese

unread,
Aug 4, 2015, 9:04:04 AM8/4/15
to Couchbase Mobile
sceneNumber is a string and they appear in the order the docs where created. 

Is it possible to have the results returned sorted by sceneNumber?

Todd

Todd Freese

unread,
Aug 4, 2015, 9:19:09 AM8/4/15
to Couchbase Mobile
Actually, I solved my problem. Thanks for the tip on using {}.

Turned out I had some bad data in the database. Once I resolved that, it started working as expected.

Todd

Todd Freese

unread,
Aug 4, 2015, 9:33:29 AM8/4/15
to Couchbase Mobile
But I do have one more question....

My SG views are returning docs with ids like "id": "-xx5gw4hcsHB48F4eCCrWGn" in addition to docs with normal UUID id's.

I'm assuming these are leaf revisions. The question is why are they getting returned by my view. Should the SG Views filter out this info or do I need to do this in my map block? 

Todd

Jens Alfke

unread,
Aug 4, 2015, 12:30:50 PM8/4/15
to mobile-c...@googlegroups.com

> On Aug 4, 2015, at 6:33 AM, Todd Freese <to...@filmworkers.com> wrote:
>
> My SG views are returning docs with ids like "id": "-xx5gw4hcsHB48F4eCCrWGn" in addition to docs with normal UUID id’s.

Those are UUIDs, just ones created by Couchbase Lite 1.1. Encoding the UUID as Base64 instead of hex saves space.

—Jens

Todd Freese

unread,
Aug 4, 2015, 12:59:54 PM8/4/15
to Couchbase Mobile
Good to know. Thanks Jens!

T
Reply all
Reply to author
Forward
0 new messages