Skip to content

Commit ad4cd93

Browse files
committed
Implemented lookupByKeys. Fixes #32.
1 parent 5751ada commit ad4cd93

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2121,7 +2121,7 @@ db.collection('some-collection', function (err, collection) {
21212121

21222122
#### collection.all
21232123

2124-
`collection.all([type: string,] [callback: Callback]): Promise<Array<T>>`
2124+
`collection.all([type: string,] [callback: Callback]): Promise<Array<Object>>`
21252125

21262126
Retrieves a list of all documents in the collection.
21272127

@@ -2131,6 +2131,12 @@ If *type* is set to `"path"`, the result will be the document URI paths.
21312131

21322132
If *type* is set to `"id"` or not set, the result will be the `_id` of each document.
21332133

2134+
#### collection.byKeys
2135+
2136+
`collection.byKeys(keys: Array<string>, [callback: Callback]): Promise<Array<Object>>`
2137+
2138+
Retrieves a list of the documents with the given keys in the collection.
2139+
21342140
### DocumentCollection API
21352141

21362142
The *DocumentCollection API* extends the [*Collection API* (see above)](#collection-api) with the following methods.

src/collection.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,17 @@ extend(BaseCollection.prototype, {
186186
});
187187
return promise;
188188
},
189+
byKeys(keys, cb) {
190+
var {promise, callback} = this._connection.promisify(cb);
191+
this._api.put('simple/lookup-by-keys', {
192+
collection: this.name,
193+
keys
194+
}, function (err, res) {
195+
if (err) callback(err);
196+
else callback(null, res.body.documents);
197+
});
198+
return promise;
199+
},
189200
import(data, opts, cb) {
190201
if (typeof opts === 'function') {
191202
cb = opts;

test/collection-contents.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,7 @@ describe('collection', function () {
1515
describe('all', function () {
1616
it('is missing tests');
1717
});
18+
describe('byKeys', function () {
19+
it('is missing tests');
20+
});
1821
});

0 commit comments

Comments
 (0)