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'.
pull/2/head
Jason Rhodes 11 years ago
parent 7632ac14b3
commit b3c69f67aa
  1. 6
      lib/datastore.js

@ -477,9 +477,9 @@ Datastore.prototype._update = function (query, updateQuery, options, cb) {
} else { } else {
// The upserted document is the query (since for now queries have the same structure as // The upserted document is the query (since for now queries have the same structure as
// documents), modified by the updateQuery // 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); } 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; module.exports = Datastore;

Loading…
Cancel
Save