|
|
|
@ -377,12 +377,25 @@ Datastore.prototype.count = function(query, callback) { |
|
|
|
|
* If no callback is passed, we return the cursor so that user can limit, skip and finally exec |
|
|
|
|
* @param {Object} query MongoDB-style query |
|
|
|
|
*/ |
|
|
|
|
Datastore.prototype.find = function (query, callback) { |
|
|
|
|
Datastore.prototype.find = function (query, projection, callback) { |
|
|
|
|
switch (arguments.length) { |
|
|
|
|
case 1: |
|
|
|
|
projection = {}; |
|
|
|
|
// callback is undefined, will return a cursor
|
|
|
|
|
break; |
|
|
|
|
case 2: |
|
|
|
|
if (typeof projection === 'function') { |
|
|
|
|
callback = projection; |
|
|
|
|
projection = {}; |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var cursor = new Cursor(this, query, function(err, docs, callback) { |
|
|
|
|
var res = [], i; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (err) { return callback(err); } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < docs.length; i += 1) { |
|
|
|
|
res.push(model.deepCopy(docs[i])); |
|
|
|
|
} |
|
|
|
@ -407,7 +420,7 @@ Datastore.prototype.findOne = function (query, callback) { |
|
|
|
|
if (docs.length === 1) { |
|
|
|
|
return callback(null, model.deepCopy(docs[0])); |
|
|
|
|
} else { |
|
|
|
|
return callback(null, null);
|
|
|
|
|
return callback(null, null); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
@ -547,4 +560,6 @@ Datastore.prototype.remove = function () { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = Datastore; |
|
|
|
|