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. 4
      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);
});
}
});

Loading…
Cancel
Save