Thanks for the reply. Sorry, I should have stated I am aware of these options. It is not exactly what I am looking for. The issues with this approach are:
-
There is significant performance hit for using any one of these options that make them basically completely impractical to use in any production environment where any sensible performance is needed. I admit it is very dependent on setup and hardware, but just adding persistTo: 1
locally adds anywhere from around 100 to 200 ms to a single insert call (and I am on an SSD). You can imagine how this slows down REST API’s significantly. Avoiding the flag, understandably, cuts operation time to basically nothing, ie. single digit ms usually.
-
It is very useful to execute the database operation as normal and as fast as possible, but to know when a document is persisted or replicated. The calling client code doesn’t really care that the doc is persisted or replicated as part of the db op to return to user; but that it is done eventually and we may want to perform actions when that does happen.
-
Depending on situation, context and settings, durability requirements failures are quite common, thus reducing the usefulness of these options at actual call time.
What I am looking for is more of an async solution. I would like to know when persisted and replicated events occur without adding that as a synchronous requirement to my db operation.
What I think would be more useful is an API that would allow async observability, perhaps using EventEmmiter interface. Something like:
var observer = myBucket.observe('document_name'); // returns an EventEmitter
observer.on('persisted', function(eventData) {
console.log(eventData);
// do whatever. force refresh view of a design document
});
observer.on('replicated', function(eventData) {
console.log(eventData);
// do whatever.
});
myBucket.insert('document_name', { some: 'value' }, function(err, res) {
if (err) {
console.log('operation failed', err);
return;
}
console.log('success!', res);
});
Or perhaps using an options param:
myBucket.insert('document_name', { some: 'value' }, {observe: true}, function(err, res) {
if (err) {
console.log('operation failed', err);
return;
}
// res implements EventEmitter interface
res.on('persisted', function(eventData) {
console.log(eventData);
// do whatever. force refresh view of a design document
});
res.on('replicated', function(eventData) {
console.log(eventData);
// do whatever.
});
console.log('success!', res);
});
Another useful thing would be a global emitter perhaps:
myBucket.on('persisted', function(key, eventData), function({
console.log('persisted document with key: %s', key);
}));