0

Lets say I have 4 documents in my bucket:
doc-1:

{
  "created_time": 1435819571221,
  "field_1": false,
  "field_2": false,
  "version": 2
}

doc-2:

{
  "created_time": 1435819571221,
  "field_1": true,
  "field_2": false,
  "version": 3
}

doc-3:

{
  "created_time": 1435819571221,
  "field_1": true,
  "field_2": true,
  "version": 10
}

doc-4:

{
  "created_time": 1435819571221,
  "field_1": true,
  "field_2": true,
  "version": 12
}

I want to query all the docs with version >= 10.
So I created a view that emits the version as key, thinking i could query with startKey x to get all versions newer than x.

Problem is couchbase base does the querying lexicographically.
So in the example above I will get back all 4 docs.
How can i get it to work on natural order of numbers?

Thanks, Michael

belostoky
  • 934
  • 2
  • 11
  • 22

2 Answers2

1

It is possible I'm not understanding correctly, but when I tried what you've mentioned, I received two results as expected:

To test I did the following:

  1. Created a new bucket
  2. Created four documents with exactly the data that you've specified
  3. Created a view with the following code (I don't think StackOverflow formats correctly):

    function (doc, meta) { emit(doc.version, null); }

  4. Added a filter to the view to have a startKey of 10, then queried for results

In the results I received version 10 and version 12.

Documentation I referred to is found here:

http://docs.couchbase.com/admin/admin/Views/views-querySample.html

Let me know if I misunderstood or if this solves your problem.

Regards,

Nic Raboy
  • 3,143
  • 24
  • 26
0

Okay its a mistake of mine - in my example the key I emit is a number, but in the scenario that I am actually facing the keys are strings with numbers like :
"id::20::some@email1.com", "id::22::some@email2.com", "id::100::some@email3.com".
So when I did a range query with startKey="id::20" it didn't returned the "id::100::some@email3.com" document because it sorts lexicographically...

Thanks - u helped me understand my mistake...
Michael

belostoky
  • 934
  • 2
  • 11
  • 22