|
|
@ -390,7 +390,7 @@ Datastore.prototype.count = function() { |
|
|
|
* |
|
|
|
* |
|
|
|
* @api private Use find |
|
|
|
* @api private Use find |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
Datastore.prototype._find = function (query, callback) { |
|
|
|
Datastore.prototype.find = function (query, callback) { |
|
|
|
var cursor = new Cursor(this, query); |
|
|
|
var cursor = new Cursor(this, query); |
|
|
|
|
|
|
|
|
|
|
|
if (typeof callback === 'function') { |
|
|
|
if (typeof callback === 'function') { |
|
|
@ -400,9 +400,9 @@ Datastore.prototype._find = function (query, callback) { |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
Datastore.prototype.find = function () { |
|
|
|
// Datastore.prototype.find = function () {
|
|
|
|
this.executor.push({ this: this, fn: this._find, arguments: arguments }); |
|
|
|
// this.executor.push({ this: this, fn: this._find, arguments: arguments });
|
|
|
|
}; |
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -411,7 +411,7 @@ Datastore.prototype.find = function () { |
|
|
|
* |
|
|
|
* |
|
|
|
* @api private Use findOne |
|
|
|
* @api private Use findOne |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
Datastore.prototype._findOne = function (query, callback) { |
|
|
|
Datastore.prototype.findOne = function (query, callback) { |
|
|
|
var cursor = new Cursor(this, query); |
|
|
|
var cursor = new Cursor(this, query); |
|
|
|
cursor.limit(1); |
|
|
|
cursor.limit(1); |
|
|
|
cursor.exec(function (err, docs) { |
|
|
|
cursor.exec(function (err, docs) { |
|
|
@ -423,9 +423,9 @@ Datastore.prototype._findOne = function (query, callback) { |
|
|
|
}); |
|
|
|
}); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
Datastore.prototype.findOne = function () { |
|
|
|
// Datastore.prototype.findOne = function () {
|
|
|
|
this.executor.push({ this: this, fn: this._findOne, arguments: arguments }); |
|
|
|
// this.executor.push({ this: this, fn: this._findOne, arguments: arguments });
|
|
|
|
}; |
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -457,9 +457,11 @@ Datastore.prototype._update = function (query, updateQuery, options, cb) { |
|
|
|
function (cb) { // If upsert option is set, check whether we need to insert the doc
|
|
|
|
function (cb) { // If upsert option is set, check whether we need to insert the doc
|
|
|
|
if (!upsert) { return cb(); } |
|
|
|
if (!upsert) { return cb(); } |
|
|
|
|
|
|
|
|
|
|
|
self._findOne(query, function (err, doc) { |
|
|
|
// Need to use an internal function not tied to the executor to avoid deadlock
|
|
|
|
|
|
|
|
var cursor = new Cursor(self, query); |
|
|
|
|
|
|
|
cursor.limit(1)._exec(function (err, docs) { |
|
|
|
if (err) { return callback(err); } |
|
|
|
if (err) { return callback(err); } |
|
|
|
if (doc) { |
|
|
|
if (docs.length === 1) { |
|
|
|
return cb(); |
|
|
|
return cb(); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
return self._insert(model.modify(query, updateQuery), function (err) { |
|
|
|
return self._insert(model.modify(query, updateQuery), function (err) { |
|
|
|