Update a document in the database by key

@param {String} key
@param {Object} updates - updates to apply to document
@return {Promise}
323371
function(key, updates) {
      var that = this;

      if (!this._key || !key) {
        return Promise.reject(new Error('No unique key specified'));
      }

      return this.readByKey(key).then(function(doc) {
        return that._updateDoc(doc, updates);
      });
    }
886145
function update(annotationObject, changeSet) {
  const updatedAnnotation = Object.assign({}, annotationObject, changeSet);

  let changeDetected = false;
  Object.keys(updatedAnnotation).forEach((key) => {
    if (updatedAnnotation[key] !== annotationObject[key]) {
      changeDetected = true;
    }
  });

  if (changeDetected) {
    generation += 1;
    updatedAnnotation.generation = generation;
  }

  return updatedAnnotation;
}
778660
function updateDocument(existingDoc, newDoc, id, db, f_ShouldUpdate, shouldCreate, f_Merge, callback) {
    if (!f_ShouldUpdate) {
        f_ShouldUpdate = always;
    }

    if (!f_Merge) {
        f_Merge = useNewVersion;
    }

    // If we never grabbed the existing document from the DB, fetch it and try again.
    if (!existingDoc) {
        return db.get(id, function (err, r) {
            // If the fetch came back with nothing, attempt to do a fresh insert unless the user
            // doesn't want documents to be created.
            if (err && (err.error === "not_found")) {
                if (!shouldCreate)
                    // Don't create a document where one didn't exist, if the user so desires.
                    return callback(null, null);

                return db.insert(newDoc, id, function (err, r) {
                    // If someone beat us here, we should retry this whole operation.
                    if (err && err.error === "conflict")
                        return updateDocument(null, newDoc, id, db, f_ShouldUpdate, shouldCreate, f_Merge, callback);

                    // If anything else happened, we should bail.
                    if (err)
                        return callback("Could not fetch existing document: " + err.toString());

                    // The insert worked.  We're done.
                    return callback(null, extend({}, newDoc, {_rev: r.rev}));
                });
            }

            // If the fetch came back with any other error, bail.
            if (err)
                return callback("Could not fetch existing document: " + err.toString());

            // We got the document.  Let's try the update again.
            return updateDocument(r, newDoc, id, db, f_ShouldUpdate, shouldCreate, f_Merge, callback);
        });
    }

    if (!f_ShouldUpdate(existingDoc, newDoc)) {
        return callback(null, existingDoc);
    }

    // Before merging, record that we want to undelete a document that has been deleted.
    var mergedDoc = f_Merge(omit(existingDoc, "_deleted"), newDoc);
    if (!mergedDoc || typeof mergedDoc !== "object" || mergedDoc instanceof Error) {
        // Allow a user defined merge algorithm to say ``sorry...can't merge'' by returning a non-object or Error.
        // Bubble this error, so that the user can then test for it in their callback.
        return callback(mergedDoc);
    }

    // It's essential that we specify a revision or this will never terminate.
    // It's probably not a good idea to trust a user-specified merge function to do this.
    mergedDoc = extend({}, mergedDoc, { _rev: existingDoc._rev });

    // The document exists, and is out of date.  We need to overwrite it.
    db.insert(
        mergedDoc,
        id,
        function (err, result) {
            // If someone beat us here, we need to try the whole thing again.
            if (err && err.error === "conflict")
                return updateDocument(null, newDoc, id, db, f_ShouldUpdate, shouldCreate, f_Merge, callback);

            // If anything else happened, bail.
            if (err)
                return callback("Could not update the document to the proposed version: " + err.toString());

            // Update the new document's _rev
            mergedDoc._rev = result.rev;

            // The replacement worked.  We're done.  Finally!
            return callback(null, mergedDoc);
        }
    );
}
1193508
public static Update update(Update... update) {
        if (update.length == 1) {
            return update[0];
        } else {
            Update x = new Update(true);
            for (Update u : update) {
                ((ArrayNode) x.node).add(u.toJson());
            }
            return x;
        }
    }
1169121
function doUpdate (root, entry, cb) {
    entry = utils.updateEntry(root, entry, ['dateDetected'])

    // console.log('overwriting', root, 'with', entryJSON, 'resulting in', entry.toJSON())
    put(entry, cb)
  }
183645
def create_update():
    
    update = upkey("update").setResultsName("action")
    returns, none, all_, updated, old, new = map(
        upkey, ["returns", "none", "all", "updated", "old", "new"]
    )
    return_ = returns + Group(
        none | (all_ + old) | (all_ + new) | (updated + old) | (updated + new)
    ).setResultsName("returns")
    return (
        update
        + table
        + update_expr
        + Optional(keys_in)
        + Optional(where)
        + Optional(using)
        + Optional(return_)
        + Optional(throttle)
    )
1079725
public static CollectionSchemaUpdate update(String key, IOperation operation) {
    return new CollectionSchemaUpdate().set(key, operation);
  }
505692
function(key) {
      var that = this;

      if (!this._key || !key) {
        return Promise.reject(new Error('No unique key specified'));
      }

      var props = {};
      props[this._key] = key;

      return this._dbApi.find(props).then(function(docs) {
        return that._readDoc(docs[0]);
      });
    }
851855
def update(self, document_id, update_spec, namespace, timestamp):
        
        document = self.doc_dict[document_id].doc
        updated = self.apply_update(document, update_spec)
        if "_id" in updated:
            updated.pop("_id")
        updated[self.unique_key] = document_id
        self.upsert(updated, namespace, timestamp)
        return updated
61305
function(key) {
      var that = this;

      if (!this._key || !key) {
        return Promise.reject(new Error('No unique key specified'));
      }

      return this.readByKey(key).then(function(doc) {
        return that.delete(doc[that._dbType.id]);
      });
    }
1090121
function update(item, model, data, funcParams) {
    var working = [];
    var definedByData = [];

    _.forEach(data, function(value, key) {
        if (_.isFunction(value)) {
            working.push(Promise.resolve(value()).then(function(val) {
                item[key] = val;
            }));
        } else item[key] = value;
        definedByData.push(value);
    });

    _.forEach(model.itemDef, function(value, key) {
        if (value && value.__precalc) {
            var func = value.__precalc, previousVal = data[key];
            working.push(Promise.resolve(func.call(item, previousVal, funcParams || {})).then(function(val) {
                item[key] = (val && val._stWrapped) ? val.val : val;
            }));
        } // if the property has not been set from the itemDef yet. This allows item def properties to be changed
        else if (!_.has(item, key) || definedByData.indexOf(key) !== -1) item[key] = value;
    });

    return Promise.all(working);
}
296365
public WriteResult<T, K> updateById(K id, DBUpdate.Builder update) throws MongoException {
        return this.update(createIdQuery(id), update.serialiseAndGet(objectMapper));
    }
253794
def update(key, definition, options = {})
      custom_params = options[:dc] ? use_named_parameter('dc', options[:dc]) : nil
      ret = send_put_request(@conn, ["/v1/query/#{key}"], options, definition, custom_params)
      ret.status == 200
    end
557900
function update() {
  for (var
    tmp,
    promise = false,
    updates = this.updates,
    template = this.chunks,
    out = [template[0]],
    i = 1,
    length = arguments.length;
    i < length; i++
  ) {
    tmp = arguments[i];
    if (
      (typeof tmp === 'object' && tmp !== null)
      &&
      (typeof tmp.then === 'function' || 'placeholder' in tmp)
    ) {
      promise = true;
      out.push(
        ('placeholder' in tmp ? invokeAtDistance(tmp, false) : tmp)
          .then(updates[i - 1]),
        template[i]
      );
    } else {
      out.push(updates[i - 1](tmp), template[i]);
    }
  }
  return promise ? Promise.all(out).then(asBuffer) : asBuffer(out);
}
549617
function (soajs, combo, cb) {
        soajs.mongoDb.update(combo.collection, combo.condition, combo.whattoupdate, cb);
    }
756425
def update(key, ctx)
      resp = _request_endpoint(ctx)
      if resp && resp.endpoints
        resp.endpoints.each { |e| self[key] = e }
      end
    end
1001284
public String updateCollection(final Key key) {
        if (key.getCollection() == null && key.getType() == null) {
            throw new IllegalStateException("Key is invalid! " + toString());
        } else if (key.getCollection() == null) {
            key.setCollection(getMappedClass(key.getType()).getCollectionName());
        }

        return key.getCollection();
    }