Again. Three multiple keys. Sorting


#1

Hi.

@avsej

Thanks for your reply.

Here is my modified code:

View:

function (doc, meta) {
  if (meta.type == "json" && doc.type && doc.type == "fileCouple") {
    // Check if doc is JSON
    emit([doc.file, doc.case, doc.prevFile], {
      'docId': doc.docId,
      'createdAt': doc.createdAt,
      'updatedAt': doc.updatedAt,
      'file': doc.file,
      'prevFile': doc.prevFile,
      'case': doc.case
    });
      
    } else {
    }
}

PHP:

$startKey = json_encode([$cbFileShowNext[$this->file], 1]);
$endKey = json_encode([$cbFileShowNext[$this->file], 100]);
$query = CouchbaseViewQuery::from("fileCouple", 'fileCoupleChain')->custom(["startkey" => $startKey, "endkey" => $endKey])->stale(CouchbaseViewQuery::UPDATE_BEFORE);

This code works.

Now my question is: how do the sorting in descending order.

When I add a string.

->order(CouchbaseViewQuery::ORDER_DESCENDING)

The result is lost.

I have:

couchbase cli 2.2.0beta2
Ubuntu 14.04
PHP 7

Thankee!


#2

@Kozlov you have to swap start/end keys


#3

I tried this code.

$startKey = json_encode([$cbFileShowNext[$this->file], 100]);
$endKey = json_encode([$cbFileShowNext[$this->file], 1]);
$query = CouchbaseViewQuery::from("fileCouple", 'fileCoupleChain')->custom(["startkey" => $startKey, "endkey" => $endKey])->stale(CouchbaseViewQuery::UPDATE_BEFORE);

The result is empty.

And this.

$query = CouchbaseViewQuery::from("fileCouple", 'fileCoupleChain')->custom(["endkey" => $endKey, "startkey" => $startKey])->stale(CouchbaseViewQuery::UPDATE_BEFORE);

Sort in ascending remained.

What am I doing wrong?


#4

forgot ->order(CouchbaseViewQuery::ORDER_DESCENDING)?


#5

Yes you are right!

Super! Everything works correctly.

Again, Thank you @avsej.