diff --git a/lib/cursor.js b/lib/cursor.js index f36614a..61f9e98 100644 --- a/lib/cursor.js +++ b/lib/cursor.js @@ -46,9 +46,11 @@ Cursor.prototype.sort = function(sortQuery) { /** * Get all matching elements + * This is an internal function, use exec which uses the executor + * * @param {Function} callback - Signature: err, results */ - Cursor.prototype.exec = function(callback) { +Cursor.prototype.exec = function(callback) { var candidates = this.db.getCandidates(this.query) , res = [], added = 0, skipped = 0, self = this , i @@ -93,6 +95,12 @@ Cursor.prototype.sort = function(sortQuery) { return callback(null, res); }; +// Cursor.prototype.exec = function () { + // console.log("=============IN EXEC"); + // this.db.executor.push({ this: this, fn: this._exec, arguments: arguments }); +// }; + + // Interface module.exports = Cursor; \ No newline at end of file diff --git a/lib/datastore.js b/lib/datastore.js index acf4a8a..470d9f8 100644 --- a/lib/datastore.js +++ b/lib/datastore.js @@ -462,8 +462,6 @@ Datastore.prototype._update = function (query, updateQuery, options, cb) { if (doc) { return cb(); } else { - // The upserted document is the query (since for now queries have the same structure as - // documents), modified by the updateQuery return self._insert(model.modify(query, updateQuery), function (err) { if (err) { return callback(err); } return callback(null, 1, true); diff --git a/test/cursor.test.js b/test/cursor.test.js index d552085..10191ba 100644 --- a/test/cursor.test.js +++ b/test/cursor.test.js @@ -531,6 +531,10 @@ describe('Cursor', function () { } ], done); }); + + it.skip('Multiple consecutive sorts', function(done) { + done(); + }); }); // ===== End of 'Sorting' ===== diff --git a/test/db.test.js b/test/db.test.js index 1dcf067..7a387b9 100644 --- a/test/db.test.js +++ b/test/db.test.js @@ -602,6 +602,25 @@ describe('Database', function () { }); }); }); + + it.only('Can use sort, skip and limit if the callback is not passed to find but to exec', function (done) { + d.insert({ a: 2, hello: 'world' }, function () { + d.insert({ a: 24, hello: 'earth' }, function () { + d.insert({ a: 13, hello: 'blueplanet' }, function () { + d.insert({ a: 15, hello: 'home' }, function () { + d.find({}).sort({ a: 1 }).limit(2).exec(function (err, docs) { + assert.isNull(err); + docs.length.should.equal(2); + docs[0].hello.should.equal('world'); + docs[1].hello.should.equal('blueplanet'); + done(); + }); + }); + }); + }); + }); + }); + }); // ==== End of 'Find' ==== //