From b3c69f67aa1b274b9a017073783803d83ede8fa8 Mon Sep 17 00:00:00 2001 From: Jason Rhodes Date: Fri, 24 Jan 2014 20:55:49 -0500 Subject: [PATCH] Made upsert return reference to created document When upsert is true and it can't find an existing record to match the query, it calls self._insert which will return a ref to the newly created doc as the 2nd param to the callback, but the upsert logic wasn't catching a 2nd param (only the first param: err) so I just added the 2nd param as 'newDoc' and passed it to the upsert callback instead of 'true'. --- lib/datastore.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/datastore.js b/lib/datastore.js index bf5792f..58bf91f 100644 --- a/lib/datastore.js +++ b/lib/datastore.js @@ -477,9 +477,9 @@ Datastore.prototype._update = function (query, updateQuery, options, 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) { + return self._insert(model.modify(query, updateQuery), function (err, newDoc) { if (err) { return callback(err); } - return callback(null, 1, true); + return callback(null, 1, newDoc); }); } }); @@ -567,4 +567,4 @@ Datastore.prototype.remove = function () { }; -module.exports = Datastore; \ No newline at end of file +module.exports = Datastore;