WarmasterMazuran
WarmasterMazuran

Reputation: 59

Cloudant search documents that appear after certain id

There is a cloudant database that stores some documents.

There is also mobile app that takes those documents by using search indexes.

Question is: Is it possible to make query "get me all indexes that appear after this one"?

For example: I start app, and get from database documents with id 'aaa','aab' and 'aac'. I want to store last id - 'aac' - in memory of my app. Then, when I start the app, I want to get from database documents that appeared after 'aac'.

I think the main problem will be, that _ids are assigned as random strings, but I want to be sure.

Upvotes: 0

Views: 227

Answers (1)

vabarbosa
vabarbosa

Reputation: 706

when searching the index, try including the selector field in JSON object of the request body:

{
  "selector": {
    "_id": {
      "$gt": "the_previous_id"
    }
  },
  "sort": [
    {
      "_id": "asc"
    }
  ]
}

in addition, from https://docs.cloudant.com/document.html:

"The _id field is either created by you, or generated automatically as a UUID by Cloudant."

therefore, it is possible to provide your own _ids when creating a document if the Cloudant generated _ids are not working for you.

condition operators:
https://docs.cloudant.com/cloudant_query.html#condition-operators

Upvotes: 0

Related Questions