Sort by date after requesting multiple keys

Document structure:

{
  "Type":"post"
  "LastModified":"2010-11-01 21:55",
  "CategoryID":3,
  "ID":12
}

The presence of a large number of different mail documents in different categories is great. But I can’t understand how to make a presentation that returns documents sorted by date, when choosing those that belong, for example, to categories 3 and 5. Categories are unknown, the limit query should work.

I tried different approaches to presentation, but nothing comes close to achieving the desired result.

In SQL, this can probably be done as follows:

SELECT * FROM document WHERE document.CategoryID in (3,5) ORDER BY document.LastModified DESC;

I could simply request such a representation as the required number of times, manually sort and swap data:

function(doc) {
  emit(doc.CategoryID, doc.ID);
}

Does anyone know if it's possible to avoid this and just have couchdb a little smarter?

+3
source share
1

.

  • CategoryID, LastModified .

    function(doc) {
        emit([doc.CategoryID, doc.LastModified], null);
    }
    

    ?startkey=[3]&endkey=[3, {}], CategoryID=3, LastModified. , .

  • couchdb-lucene . couchdb-lucene .

+4

Source: https://habr.com/ru/post/1773680/


All Articles