Permalink
Browse files

(#6039) - include id in all bulk_docs results (#6047)

CouchDB already includes an id field for each result in a _bulk_docs response. For non-http adapters, ensure we do the same.

It seems simpler to do this in the core adapter code rather than patch up every individual storage engine.
  • Loading branch information...
1 parent 587ba8f commit 2553fd77bf341976f205a5e7ae8352775dee7409 @willholley willholley committed on GitHub Dec 22, 2016
Showing with 12 additions and 1 deletion.
  1. +10 −1 packages/node_modules/pouchdb-core/src/adapter.js
  2. +2 −0 tests/integration/test.bulk_docs.js
@@ -826,7 +826,8 @@ AbstractPouchDB.prototype.bulkDocs =
}
}
- if (!opts.new_edits && this.type() !== 'http') {
+ var adapter = this;
+ if (!opts.new_edits && adapter.type() !== 'http') {
// ensure revisions of the same doc are sorted, so that
// the local adapter processes them correctly (#2935)
req.docs.sort(compareByIdThenRev);
@@ -844,6 +845,14 @@ AbstractPouchDB.prototype.bulkDocs =
return x.error;
});
}
+
+ // add ids for error / conflict responses
+ // not required for CouchDB
+ if (adapter.type() !== 'http') {
+ for (var i = 0, l = res.length; i < l; i++) {
+ res[i].id = res[i].id || req.docs[i]._id;
+ }
+ }
callback(null, res);
});
});
@@ -67,6 +67,8 @@ adapters.forEach(function (adapter) {
results[0].name.should.equal(
'conflict', 'First doc should be in conflict');
should.not.exist(results[0].rev, 'no rev in conflict');
+ should.exist(results[0].id);
+ results[0].id.should.equal("0");
for (i = 1; i < 5; i++) {
results[i].id.should.equal(i.toString());
should.exist(results[i].rev);

0 comments on commit 2553fd7

Please sign in to comment.