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