Couchbase startkey_docid and complex key

The call below with a matching result set returns a result that does not start with doc id a4a6cf44-8a82-494a-a2b9-f6a3ec629f17. As shown in the example below, the top 3 keys are identical, but startkey_docid has no effect.

Just a couple of questions around this

  • Will startkey_docid work correctly with a complex key? (This seems to work for couchdb)
  • If yes to the above, is the use of dateToArray (doc.created) in our view a source of the problem?
  • This is mistake?

View:

function (doc, meta) 
{
  if(meta.type == "json" && doc.type == "POST") 
  {
    emit([doc.category, dateToArray(doc.created), doc.visibility], null);
  }
}

Call:

?startkey=["auto",[2013,10,10,23,12,0],"EVERYONE"]&endkey=["auto",[2013,12,11,23,12,0],"EVERYONE"]&startkey_docid=a4a6cf44-8a82-494a-a2b9-f6a3ec629f17

Result:

{
    total_rows: 20,
    rows: [{
        id: "a4a6cf44-8a82",
        key: ["auto", [2013, 11, 8, 1, 17, 46], "EVERYONE"],
        value: null
    }, {
        id: "a4a6cf44-8a82-494a-a2b9",
        key: ["auto", [2013, 11, 8, 1, 17, 46], "EVERYONE"],
        value: null
    }, {
        id: "a4a6cf44-8a82-494a-a2b9-f6a3ec629f17",
        key: ["auto", [2013, 11, 8, 1, 17, 46], "EVERYONE"],
        value: null
    }, {
        id: "41070cfc-a85c-424c-9b87-fce0616c77c1",
        key: ["auto", [
        2013, 11, 11, 20, 28, 21], "EVERYONE"],
        value: null
    }, {
        id: "bb275e3c-54da-4e85-8cc3-21defff4e278",
        key: ["auto", [
        2013, 11, 13, 1, 41, 7], "EVERYONE"],
        value: null
    }]
}

An example of a data set. post_id is the document id.

{
    type: "POST",
    post_id: "a4a6cf44-8a82",
    visibility: "EVERYONE",
    userID: "<user_id>",
    title: "Some title 1",
    category: "auto",
    description: "",
    created: "2013-11-07 17:17:46 -0800",
    modified: "2013-11-07 17:17:46 -0800"
}, {
    type: "POST",
    post_id: "a4a6cf44-8a82-494a-a2b9",
    visibility: "EVERYONE",
    userID: "<user_id>",
    title: "Some title 2",
    category: "auto",
    description: "",
    created: "2013-11-07 17:17:46 -0800",
    modified: "2013-11-07 17:17:46 -0800"
}, {
    type: "POST",
    post_id: "a4a6cf44-8a82-494a-a2b9-f6a3ec629f17",
    visibility: "EVERYONE",
    userID: "<user_id>",
    title: "Some title 3",
    category: "auto",
    description: "",
    created: "2013-11-07 17:17:46 -0800",
    modified: "2013-11-07 17:17:46 -0800"
}, {
    type: "POST",
    post_id: "41070cfc-a85c-424c-9b87-fce0616c77c1",
    visibility: "EVERYONE",
    userID: "<user_id>",
    title: "Some title 4",
    category: "auto",
    description: "",
    created: "2013-11-11 12:28:21 -0800",
    modified: "2013-11-11 12:28:21 -0800"
}, {
    type: "POST",
    post_id: "bb275e3c-54da-4e85-8cc3-21defff4e278",
    visibility: "EVERYONE",
    userID: "<user_id>",
    title: "Some title 5",
    category: "auto",
    description: "",
    created: "2013-11-12 17:41:07 -0800",
    modified: "2013-11-12 17:41:07 -0800"
}
+4
source share
3 answers

, , , , .


9 000 , , title, year, rating, genre .., MovieIndexView MovieIndex ( ) :

function (doc) {
    emit([doc.rating, doc.year], doc);
}

, , , OP:

- Request -
GET /movies_db/_design/MovieIndex/_view/MovieIndexView?
startkey=["R",{}]
&endkey=["R",0]
&descending=true
&limit=6

- Response -
{
    "total_rows": 9411,
    "offset": 1,
    "rows": [
        {
            "id": "2802144",
            "key": [
                "R",
                2014
            ],
            "value": {
                "_id": "2802144",
                "_rev": "1-924e12ba1f1144e3a453bbd8978acc5c",
                "title": "Kingsman: The Secret Service",
                "year": 2014,
                "rating": "R",
                "runtime": "129 min",
                "genre": [
                    "Action",
                    "Adventure",
                    "Comedy"
                ],
                "director": "Matthew Vaughn"
            }
        },
        <...>
        {
            "id": "2278388",
            "key": [
                "R",
                2014
            ],
            "value": {
                "_id": "2278388",
                "_rev": "1-c38b7f5eb43abfd59fb8514277290e46",
                "title": "The Grand Budapest Hotel",
                "year": 2014,
                "rating": "R",
                "runtime": "99 min",
                "genre": [
                    "Adventure",
                    "Comedy",
                    "Drama"
                ],
                "director": "Wes Anderson"
            }
        }
    ]
}

, 6 , limit ( ).

. startkey key , endkey :

startkey=["R",2014]
&endkey=["R",0]
&descending=true
&limit=6

? , startkey ( , ), . , , , , key.

startkey_docid :

- Request -
GET /movies_db/_design/MovieIndexView/_view/MovieIndex?
startkey=["R",2014]
&endkey=["R",0]
&descending=true
&limit=6
&startkey_docid=2278388

, , .

The Takeaway

A startkey_docid startkey .

, , .


CouchDB: http://docs.couchdb.org/en/latest/couchapp/views/collation.html

: http://grokbase.com/t/couchdb/user/091defx51x/sort-by-date-and-find-by-key

SO: fooobar.com/questions/1513185/...

0

More information on how to use startkey_docidit can be found here: http://blog.couchbase.com/startkeydocid-behaviour

-1
source

All Articles