Browse Source

Add the cursor.map function

saintedlama/travis-non-legacy
Eduardo Sorribas 11 years ago
parent
commit
a3e50ef13b
  1. 7
      index.js
  2. 18
      tests/test-cursor-map.js

7
index.js

@ -88,6 +88,13 @@ Cursor.prototype.destroy = function() {
this.push(null);
};
Cursor.prototype.map = function(mapfn, callback) {
this.toArray(function(err, arr) {
if (err) return callback(err);
callback(null, arr.map(mapfn))
});
};
Cursor.prototype._apply = function(fn, args) {
this._get(function(err, cursor) {
if (err) return getCallback(args)(err);

18
tests/test-cursor-map.js

@ -0,0 +1,18 @@
var assert = require('assert');
var insert = require('./insert');
insert([{
hello:'world1'
},{
hello:'world2'
}], function(db, done) {
var cursor = db.a.find();
cursor.map(function(x) {
return x.hello
}, function(err, res) {
assert.equal(res[0], 'world1');
assert.equal(res[1], 'world2');
done();
});
});
Loading…
Cancel
Save