Frankra
Frankra

Reputation: 133

CouchDB seq number changes when adding include_docs=true

While playing around with the _changes API from CouchDB (2.1.1), I noticed that the seq number of the resulting records is different when I add the ?include_docs=true. Is this something expected? If yes, can somebody help me understand the logic behind it?

Further info:

Test Files created

Call with ?include_docs=true

enter image description here

Call without ?include_docs=true

enter image description here

As you can see, the id value on both requests is different looking by the order of entries on the response, also, the seq hash looks like the same but its 'string part' is different by the end of it. So my question is, why they are not the same, given that I am only wanting to add the doc reference? Is this something expected? If yes, can somebody explain?

Upvotes: 0

Views: 653

Answers (1)

Juanjo Rodriguez
Juanjo Rodriguez

Reputation: 2131

You have to consider that the _changes feed is not fully ordered. The changes are being computed from the set of nodes and shards of the database. CouchDB retrieves the changes from the different shards and then combine them into a single stream.

The logic behind the sequence numbers of the changes feed is quite complex and reflects the state of each of the shards that have responded to the changes feed request.

If you decode the string part of the seq binary_to_term(couch_util:decodeBase64Url(EncodedStringHere)) you will see the state of the shards used to compose the chages entry for that doc.

The question here is that you can not rely in the changes feed order as it may change.

Upvotes: 1

Related Questions