CouchDB _changes feed behaviour with document changes in _rev only
Basically I am querying a view, requesting an update_seq
value to be returned. I then use this returned sequence number in a subsequent _changes
feed request. My expectation (which may be wrong?) is that the returned changes should be empty; since I just queried the view, and asking for changes since that view.
Normally this works fine, except when I update a document without changing its content (i.e. only the document's _rev
field changes). Now I can query the view and changes as above, but it will always give a change result pointing to this changed document. Maybe the code below explains better ...
const request = require("request-promise-native");
const _throw = e => { throw e };
// Given an 'empty' couchdb database 'test' with the following design document:
//
// _id: "_design/test",
// language: "javascript",
// views: {
// test: {
// map: function(doc) {
// if (doc.message) emit(null, doc.message);
// }
// }
// }
const db = "http://localhost:5984/test";
const get = id =>
request.get({
url: `${db}/${id}`,
json: true,
})
const post = body =>
request.post({
url: `${db}`,
json: true,
body
});
// Insert doc, or update existing doc if it already exists ...
const update = doc =>
get(doc._id)
.then(({ _rev }) => post({ ...doc, _rev }))
.catch(e => e.statusCode === 404
? post(doc)
: _throw(e))
// Query the view, make sure to get the update_seq value ...
const messages = () => request
.get({
url: `${db}/_design/test/_view/test`,
qs: { update_seq: true },
json: true
})
// Query the _changes feed for any changes since the supplied seq number
const changes = (since = "now") =>
request
.get({
url: `${db}/_changes`,
qs: { filter: "_view", view: "test/test", since },
json: true
})
// Just update the document, query the view, and then pass the returned seq to the changes feed ...
const check = async message => {
await update({ _id: "test", message });
const msgs = await messages();
console.log("messages:", msgs.rows);
const chgs = await changes(msgs.update_seq);
console.log("changes:", chgs.results, "nn");
}
// I would expect the changes results to always be empty, since I am tracking the
// changes since the seq number returned from the view (and there are no changes
// to the database inbetween). However, this is only true for when the message field
// of the document changes. Updating the doc without changing this field (i.e. just
// triggering a _rev change) causes the changes result to be always non-empty
const run_checks = async () => {
await check("1");
await check("1");
await check("2");
await check("2");
await check("2");
}
run_checks();
This gives the following results:
$ node changes.js
messages: [ { id: 'test', key: null, value: '1' } ]
changes:
messages: [ { id: 'test', key: null, value: '1' } ]
changes: [ { seq:
'55-g1AAAAH3eJzLYWBg4MhgTmEQTM4vTc5ISXIwNDLXMwBCwxygFFMiQ5L8____szKYExlygQLs5mlmqZamZikMnKV5KalpmXmpKXi0JykAySR7kAmJjPjUOYDUxaPalJpkYpZkTKxNCSAT6lFMSEqxSDM1NSXShDwWIMnQAKSAhsxHmJKaZGFoQLSPIaYsgJiyH2FKskmyhbm5CUmmHICYch9kihnER6ZpxuYgt2DqI2jaA4hpwJhgyAIAz9mJKQ',
id: 'test',
changes: [ [Object] ] } ]
messages: [ { id: 'test', key: null, value: '2' } ]
changes:
messages: [ { id: 'test', key: null, value: '2' } ]
changes: [ { seq:
'57-g1AAAAH3eJzLYWBg4MhgTmEQTM4vTc5ISXIwNDLXMwBCwxygFFMiQ5L8____szKYExlygQLs5mlmqZamZikMnKV5KalpmXmpKXi0JykAySR7kAmJjPjUOYDUxaPalJpkYpZkTKxNCSAT6lFMSEqxSDM1NSXShDwWIMnQAKSAhsxHmJKaZGFoQLSPIaYsgJiyH2FKskmyhbm5CUmmHICYch9kigXER6ZpxuYgt2DqI2jaA4hpwJhgyAIA0HWJKw',
id: 'test',
changes: [ [Object] ] } ]
messages: [ { id: 'test', key: null, value: '2' } ]
changes: [ { seq:
'58-g1AAAAIzeJyV0EsOgjAQBuBRTNSlJ9ATGKAtbVdyE6WvIEFcsdab6E30JnoTLNYESAyBNJkmbebLP5MDwCL1FKzkuZSpEnEQ0q1vT5Dbr2kCYl1VVZZ6CZzsw5yaSHMSKViWhdLmWGjV0y42tordT5h8hZAxpHDyr6dPimtp382iBY4EGprlUAuXjiAUM4SQgUIxsxWu9rLIrVG0YIE_eCdOuTvl0SgSS0YpHqU8nfKqFe4mIgbROsuo7Trt7bTWfphUiPOwnSn7AHWel-8',
id: 'test',
changes: [ [Object] ] } ]
The changes result is only empty when the actual value in the view changes ... What am I missing?
node.js couchdb
add a comment |
Basically I am querying a view, requesting an update_seq
value to be returned. I then use this returned sequence number in a subsequent _changes
feed request. My expectation (which may be wrong?) is that the returned changes should be empty; since I just queried the view, and asking for changes since that view.
Normally this works fine, except when I update a document without changing its content (i.e. only the document's _rev
field changes). Now I can query the view and changes as above, but it will always give a change result pointing to this changed document. Maybe the code below explains better ...
const request = require("request-promise-native");
const _throw = e => { throw e };
// Given an 'empty' couchdb database 'test' with the following design document:
//
// _id: "_design/test",
// language: "javascript",
// views: {
// test: {
// map: function(doc) {
// if (doc.message) emit(null, doc.message);
// }
// }
// }
const db = "http://localhost:5984/test";
const get = id =>
request.get({
url: `${db}/${id}`,
json: true,
})
const post = body =>
request.post({
url: `${db}`,
json: true,
body
});
// Insert doc, or update existing doc if it already exists ...
const update = doc =>
get(doc._id)
.then(({ _rev }) => post({ ...doc, _rev }))
.catch(e => e.statusCode === 404
? post(doc)
: _throw(e))
// Query the view, make sure to get the update_seq value ...
const messages = () => request
.get({
url: `${db}/_design/test/_view/test`,
qs: { update_seq: true },
json: true
})
// Query the _changes feed for any changes since the supplied seq number
const changes = (since = "now") =>
request
.get({
url: `${db}/_changes`,
qs: { filter: "_view", view: "test/test", since },
json: true
})
// Just update the document, query the view, and then pass the returned seq to the changes feed ...
const check = async message => {
await update({ _id: "test", message });
const msgs = await messages();
console.log("messages:", msgs.rows);
const chgs = await changes(msgs.update_seq);
console.log("changes:", chgs.results, "nn");
}
// I would expect the changes results to always be empty, since I am tracking the
// changes since the seq number returned from the view (and there are no changes
// to the database inbetween). However, this is only true for when the message field
// of the document changes. Updating the doc without changing this field (i.e. just
// triggering a _rev change) causes the changes result to be always non-empty
const run_checks = async () => {
await check("1");
await check("1");
await check("2");
await check("2");
await check("2");
}
run_checks();
This gives the following results:
$ node changes.js
messages: [ { id: 'test', key: null, value: '1' } ]
changes:
messages: [ { id: 'test', key: null, value: '1' } ]
changes: [ { seq:
'55-g1AAAAH3eJzLYWBg4MhgTmEQTM4vTc5ISXIwNDLXMwBCwxygFFMiQ5L8____szKYExlygQLs5mlmqZamZikMnKV5KalpmXmpKXi0JykAySR7kAmJjPjUOYDUxaPalJpkYpZkTKxNCSAT6lFMSEqxSDM1NSXShDwWIMnQAKSAhsxHmJKaZGFoQLSPIaYsgJiyH2FKskmyhbm5CUmmHICYch9kihnER6ZpxuYgt2DqI2jaA4hpwJhgyAIAz9mJKQ',
id: 'test',
changes: [ [Object] ] } ]
messages: [ { id: 'test', key: null, value: '2' } ]
changes:
messages: [ { id: 'test', key: null, value: '2' } ]
changes: [ { seq:
'57-g1AAAAH3eJzLYWBg4MhgTmEQTM4vTc5ISXIwNDLXMwBCwxygFFMiQ5L8____szKYExlygQLs5mlmqZamZikMnKV5KalpmXmpKXi0JykAySR7kAmJjPjUOYDUxaPalJpkYpZkTKxNCSAT6lFMSEqxSDM1NSXShDwWIMnQAKSAhsxHmJKaZGFoQLSPIaYsgJiyH2FKskmyhbm5CUmmHICYch9kigXER6ZpxuYgt2DqI2jaA4hpwJhgyAIA0HWJKw',
id: 'test',
changes: [ [Object] ] } ]
messages: [ { id: 'test', key: null, value: '2' } ]
changes: [ { seq:
'58-g1AAAAIzeJyV0EsOgjAQBuBRTNSlJ9ATGKAtbVdyE6WvIEFcsdab6E30JnoTLNYESAyBNJkmbebLP5MDwCL1FKzkuZSpEnEQ0q1vT5Dbr2kCYl1VVZZ6CZzsw5yaSHMSKViWhdLmWGjV0y42tordT5h8hZAxpHDyr6dPimtp382iBY4EGprlUAuXjiAUM4SQgUIxsxWu9rLIrVG0YIE_eCdOuTvl0SgSS0YpHqU8nfKqFe4mIgbROsuo7Trt7bTWfphUiPOwnSn7AHWel-8',
id: 'test',
changes: [ [Object] ] } ]
The changes result is only empty when the actual value in the view changes ... What am I missing?
node.js couchdb
add a comment |
Basically I am querying a view, requesting an update_seq
value to be returned. I then use this returned sequence number in a subsequent _changes
feed request. My expectation (which may be wrong?) is that the returned changes should be empty; since I just queried the view, and asking for changes since that view.
Normally this works fine, except when I update a document without changing its content (i.e. only the document's _rev
field changes). Now I can query the view and changes as above, but it will always give a change result pointing to this changed document. Maybe the code below explains better ...
const request = require("request-promise-native");
const _throw = e => { throw e };
// Given an 'empty' couchdb database 'test' with the following design document:
//
// _id: "_design/test",
// language: "javascript",
// views: {
// test: {
// map: function(doc) {
// if (doc.message) emit(null, doc.message);
// }
// }
// }
const db = "http://localhost:5984/test";
const get = id =>
request.get({
url: `${db}/${id}`,
json: true,
})
const post = body =>
request.post({
url: `${db}`,
json: true,
body
});
// Insert doc, or update existing doc if it already exists ...
const update = doc =>
get(doc._id)
.then(({ _rev }) => post({ ...doc, _rev }))
.catch(e => e.statusCode === 404
? post(doc)
: _throw(e))
// Query the view, make sure to get the update_seq value ...
const messages = () => request
.get({
url: `${db}/_design/test/_view/test`,
qs: { update_seq: true },
json: true
})
// Query the _changes feed for any changes since the supplied seq number
const changes = (since = "now") =>
request
.get({
url: `${db}/_changes`,
qs: { filter: "_view", view: "test/test", since },
json: true
})
// Just update the document, query the view, and then pass the returned seq to the changes feed ...
const check = async message => {
await update({ _id: "test", message });
const msgs = await messages();
console.log("messages:", msgs.rows);
const chgs = await changes(msgs.update_seq);
console.log("changes:", chgs.results, "nn");
}
// I would expect the changes results to always be empty, since I am tracking the
// changes since the seq number returned from the view (and there are no changes
// to the database inbetween). However, this is only true for when the message field
// of the document changes. Updating the doc without changing this field (i.e. just
// triggering a _rev change) causes the changes result to be always non-empty
const run_checks = async () => {
await check("1");
await check("1");
await check("2");
await check("2");
await check("2");
}
run_checks();
This gives the following results:
$ node changes.js
messages: [ { id: 'test', key: null, value: '1' } ]
changes:
messages: [ { id: 'test', key: null, value: '1' } ]
changes: [ { seq:
'55-g1AAAAH3eJzLYWBg4MhgTmEQTM4vTc5ISXIwNDLXMwBCwxygFFMiQ5L8____szKYExlygQLs5mlmqZamZikMnKV5KalpmXmpKXi0JykAySR7kAmJjPjUOYDUxaPalJpkYpZkTKxNCSAT6lFMSEqxSDM1NSXShDwWIMnQAKSAhsxHmJKaZGFoQLSPIaYsgJiyH2FKskmyhbm5CUmmHICYch9kihnER6ZpxuYgt2DqI2jaA4hpwJhgyAIAz9mJKQ',
id: 'test',
changes: [ [Object] ] } ]
messages: [ { id: 'test', key: null, value: '2' } ]
changes:
messages: [ { id: 'test', key: null, value: '2' } ]
changes: [ { seq:
'57-g1AAAAH3eJzLYWBg4MhgTmEQTM4vTc5ISXIwNDLXMwBCwxygFFMiQ5L8____szKYExlygQLs5mlmqZamZikMnKV5KalpmXmpKXi0JykAySR7kAmJjPjUOYDUxaPalJpkYpZkTKxNCSAT6lFMSEqxSDM1NSXShDwWIMnQAKSAhsxHmJKaZGFoQLSPIaYsgJiyH2FKskmyhbm5CUmmHICYch9kigXER6ZpxuYgt2DqI2jaA4hpwJhgyAIA0HWJKw',
id: 'test',
changes: [ [Object] ] } ]
messages: [ { id: 'test', key: null, value: '2' } ]
changes: [ { seq:
'58-g1AAAAIzeJyV0EsOgjAQBuBRTNSlJ9ATGKAtbVdyE6WvIEFcsdab6E30JnoTLNYESAyBNJkmbebLP5MDwCL1FKzkuZSpEnEQ0q1vT5Dbr2kCYl1VVZZ6CZzsw5yaSHMSKViWhdLmWGjV0y42tordT5h8hZAxpHDyr6dPimtp382iBY4EGprlUAuXjiAUM4SQgUIxsxWu9rLIrVG0YIE_eCdOuTvl0SgSS0YpHqU8nfKqFe4mIgbROsuo7Trt7bTWfphUiPOwnSn7AHWel-8',
id: 'test',
changes: [ [Object] ] } ]
The changes result is only empty when the actual value in the view changes ... What am I missing?
node.js couchdb
Basically I am querying a view, requesting an update_seq
value to be returned. I then use this returned sequence number in a subsequent _changes
feed request. My expectation (which may be wrong?) is that the returned changes should be empty; since I just queried the view, and asking for changes since that view.
Normally this works fine, except when I update a document without changing its content (i.e. only the document's _rev
field changes). Now I can query the view and changes as above, but it will always give a change result pointing to this changed document. Maybe the code below explains better ...
const request = require("request-promise-native");
const _throw = e => { throw e };
// Given an 'empty' couchdb database 'test' with the following design document:
//
// _id: "_design/test",
// language: "javascript",
// views: {
// test: {
// map: function(doc) {
// if (doc.message) emit(null, doc.message);
// }
// }
// }
const db = "http://localhost:5984/test";
const get = id =>
request.get({
url: `${db}/${id}`,
json: true,
})
const post = body =>
request.post({
url: `${db}`,
json: true,
body
});
// Insert doc, or update existing doc if it already exists ...
const update = doc =>
get(doc._id)
.then(({ _rev }) => post({ ...doc, _rev }))
.catch(e => e.statusCode === 404
? post(doc)
: _throw(e))
// Query the view, make sure to get the update_seq value ...
const messages = () => request
.get({
url: `${db}/_design/test/_view/test`,
qs: { update_seq: true },
json: true
})
// Query the _changes feed for any changes since the supplied seq number
const changes = (since = "now") =>
request
.get({
url: `${db}/_changes`,
qs: { filter: "_view", view: "test/test", since },
json: true
})
// Just update the document, query the view, and then pass the returned seq to the changes feed ...
const check = async message => {
await update({ _id: "test", message });
const msgs = await messages();
console.log("messages:", msgs.rows);
const chgs = await changes(msgs.update_seq);
console.log("changes:", chgs.results, "nn");
}
// I would expect the changes results to always be empty, since I am tracking the
// changes since the seq number returned from the view (and there are no changes
// to the database inbetween). However, this is only true for when the message field
// of the document changes. Updating the doc without changing this field (i.e. just
// triggering a _rev change) causes the changes result to be always non-empty
const run_checks = async () => {
await check("1");
await check("1");
await check("2");
await check("2");
await check("2");
}
run_checks();
This gives the following results:
$ node changes.js
messages: [ { id: 'test', key: null, value: '1' } ]
changes:
messages: [ { id: 'test', key: null, value: '1' } ]
changes: [ { seq:
'55-g1AAAAH3eJzLYWBg4MhgTmEQTM4vTc5ISXIwNDLXMwBCwxygFFMiQ5L8____szKYExlygQLs5mlmqZamZikMnKV5KalpmXmpKXi0JykAySR7kAmJjPjUOYDUxaPalJpkYpZkTKxNCSAT6lFMSEqxSDM1NSXShDwWIMnQAKSAhsxHmJKaZGFoQLSPIaYsgJiyH2FKskmyhbm5CUmmHICYch9kihnER6ZpxuYgt2DqI2jaA4hpwJhgyAIAz9mJKQ',
id: 'test',
changes: [ [Object] ] } ]
messages: [ { id: 'test', key: null, value: '2' } ]
changes:
messages: [ { id: 'test', key: null, value: '2' } ]
changes: [ { seq:
'57-g1AAAAH3eJzLYWBg4MhgTmEQTM4vTc5ISXIwNDLXMwBCwxygFFMiQ5L8____szKYExlygQLs5mlmqZamZikMnKV5KalpmXmpKXi0JykAySR7kAmJjPjUOYDUxaPalJpkYpZkTKxNCSAT6lFMSEqxSDM1NSXShDwWIMnQAKSAhsxHmJKaZGFoQLSPIaYsgJiyH2FKskmyhbm5CUmmHICYch9kigXER6ZpxuYgt2DqI2jaA4hpwJhgyAIA0HWJKw',
id: 'test',
changes: [ [Object] ] } ]
messages: [ { id: 'test', key: null, value: '2' } ]
changes: [ { seq:
'58-g1AAAAIzeJyV0EsOgjAQBuBRTNSlJ9ATGKAtbVdyE6WvIEFcsdab6E30JnoTLNYESAyBNJkmbebLP5MDwCL1FKzkuZSpEnEQ0q1vT5Dbr2kCYl1VVZZ6CZzsw5yaSHMSKViWhdLmWGjV0y42tordT5h8hZAxpHDyr6dPimtp382iBY4EGprlUAuXjiAUM4SQgUIxsxWu9rLIrVG0YIE_eCdOuTvl0SgSS0YpHqU8nfKqFe4mIgbROsuo7Trt7bTWfphUiPOwnSn7AHWel-8',
id: 'test',
changes: [ [Object] ] } ]
The changes result is only empty when the actual value in the view changes ... What am I missing?
node.js couchdb
node.js couchdb
asked Nov 22 '18 at 19:26
cenuijzacenuijza
612
612
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53437067%2fcouchdb-changes-feed-behaviour-with-document-changes-in-rev-only%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53437067%2fcouchdb-changes-feed-behaviour-with-document-changes-in-rev-only%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown