|
|
|
@ -389,7 +389,10 @@ Datastore.prototype.count = function() { |
|
|
|
|
* @param {Object} query MongoDB-style query |
|
|
|
|
*/ |
|
|
|
|
Datastore.prototype.find = function (query, callback) { |
|
|
|
|
var cursor = new Cursor(this, query); |
|
|
|
|
var cursor = new Cursor(this, query, function(err, docs, callback) { |
|
|
|
|
if (err) { return callback(err); } |
|
|
|
|
return callback(null, docs); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
if (typeof callback === 'function') { |
|
|
|
|
cursor.exec(callback); |
|
|
|
@ -404,15 +407,21 @@ Datastore.prototype.find = function (query, callback) { |
|
|
|
|
* @param {Object} query MongoDB-style query |
|
|
|
|
*/ |
|
|
|
|
Datastore.prototype.findOne = function (query, callback) { |
|
|
|
|
var cursor = new Cursor(this, query); |
|
|
|
|
cursor.limit(1); |
|
|
|
|
cursor.exec(function (err, docs) { |
|
|
|
|
if (err) { |
|
|
|
|
return callback(err); |
|
|
|
|
var cursor = new Cursor(this, query, function(err, docs, callback) { |
|
|
|
|
if (err) { return callback(err); } |
|
|
|
|
if (docs.length === 1) { |
|
|
|
|
return callback(null, docs[0]); |
|
|
|
|
} else { |
|
|
|
|
return callback(null, docs.length === 1 ? docs[0] : null); |
|
|
|
|
return callback(null, null);
|
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
cursor.limit(1); |
|
|
|
|
if (typeof callback === 'function') { |
|
|
|
|
cursor.exec(callback); |
|
|
|
|
} else { |
|
|
|
|
return cursor; |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|