0

I am developing notes app. The notes are downloaded from remote couchdb with bidirectional replication using couchdatabase lite API and then shown in listview. Now they are downloaded in indeterminate order, but I want them to be ordered by date. Other words at first I want to get the newer notes.

The question is: can replication be ordered by date field and how to achieve it in couchdatabase lite?

If not, should I use ordered PUT query instead?

Thanks for help!

borrrden
  • 33,256
  • 8
  • 74
  • 109
D. Sergeev
  • 2,285
  • 1
  • 13
  • 16
  • It is said that order isn't guaranteed but maybe I could use filtering by date? At first replicate all events for this day, then for the day before and so on http://stackoverflow.com/questions/15285520/couchdb-is-it-possible-to-control-order-of-replication – D. Sergeev Aug 23 '16 at 09:59

1 Answers1

0

So far I know, a filter doesn't sort documents. You get only a sorted Result for views.
On this site, are the rules how couchdb do the sorting for the keys in an index (http://wiki.apache.org/couchdb/View_collation). Probably you write an external nodejs process to create a temporary database and fill it with the result of a view which sorts all indices by the date field. To limit the result just add the limit=[number] parameter to the request url. Then replicate that temporary database.

On the other side just replicate everything and write then a view as described above to sort the indices by date.

Sceada
  • 513
  • 2
  • 11
  • Thanks for the answer, but using mirrored database would cost too much of resources. On the other side I can wait for the end of replication, it can be several minutes. Now I developed solution with multiple data filters (last day, last month, last year). But actually I wanted something like querying existing remote database without replication (but it seems to be impossible), and then start actual replication – D. Sergeev Aug 25 '16 at 13:12