Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fixed bug in getDoc

  • Loading branch information...
commit 8247ffd780a2aff1d663d94c7e4d8266ecf10239 1 parent ca7fa3e
Nathan authored
Showing with 11 additions and 1 deletion.
  1. +6 −1 lib/couchdb.js
  2. +5 −0 tests/couchclient.js
7 lib/couchdb.js
View
@@ -96,6 +96,9 @@ CouchClient.prototype.getRequestOptions = function(opts) {
if (typeof opts.body === "string") {
opts.body = [opts.body];
}
+ if (opts.body) {
+ opts.uri.body = opts.body;
+ }
return opts;
};
@@ -381,9 +384,11 @@ Database.prototype.allDocs = function(opts) {
*/
Database.prototype.getDoc = Database.prototype.openDoc = function(id) {
if (Array.isArray(id)) {
- return this.allDocs({
+ return Q.when(this.allDocs({
search: '?include_docs=true',
body: JSON.stringify({ keys: id })
+ }), function(res) {
+ return res.rows.map(function(x) { return x.doc; });
});
}
5 tests/couchclient.js
View
@@ -344,11 +344,16 @@ exports["test getDoc should get multiple documents"] = function(beforeExit) {
}).then(function() {
return db.getDoc(['doc1', 'doc2']);
}).then(function(res) {
+ console.log('res', res);
docs = res;
});
+ }, function(err) {
+ console.log('err', err);
});
beforeExit(function() {
assert.ok(Array.isArray(docs));
+ assert.ok(docs[0]._id === 'doc1');
+ assert.ok(docs[1]._id === 'doc2');
});
};
Please sign in to comment.
Something went wrong with that request. Please try again.