def add_update(self, selector, update, multi=False, upsert=False): """Create an update document and add it to the list of ops. """ validate_ok_for_update(update) cmd = SON([('q', selector), ('u', update), ('multi', multi), ('upsert', upsert)]) self.ops.append((_UPDATE, cmd))
def add_update(self, selector, update, multi=False, upsert=False, collation=None, array_filters=None, hint=None): """Create an update document and add it to the list of ops. """ validate_ok_for_update(update) cmd = SON([('q', selector), ('u', update), ('multi', multi), ('upsert', upsert)]) collation = validate_collation_or_none(collation) if collation is not None: self.uses_collation = True cmd['collation'] = collation if array_filters is not None: self.uses_array_filters = True cmd['arrayFilters'] = array_filters if hint is not None: self.uses_hint = True cmd['hint'] = hint if multi: # A bulk_write containing an update_many is not retryable. self.is_retryable = False self.ops.append((_UPDATE, cmd))
def update_many(self, filter, update, upsert=False, **kwargs): """Update one or more documents that match the filter. :raises ValueError: if `update` document is empty. :raises ValueError: if `update` document has fields that don't start with `$` sign. This method only allows *modification* of document (with `$set`, `$inc`, etc.), not *replacing* it. For replacing use :meth:`replace_one()` instead. :param filter: A query that matches the documents to update. :param update: update document to be used for updating or upserting. See `MongoDB Update docs <https://docs.mongodb.org/manual/tutorial/modify-documents/>`_ for allowed operators. :param upsert: If ``True``, perform an insert if no documents match the `filter`. :returns: deferred instance of :class:`pymongo.results.UpdateResult`. """ validate_ok_for_update(update) raw_response = yield self._update(filter, update, upsert, multi=True, **kwargs) defer.returnValue( UpdateResult(raw_response, self.write_concern.acknowledged))
def update_many(self, filter, update, upsert=False, **kwargs): """Update one or more documents that match the filter. :raises ValueError: if `update` document is empty. :raises ValueError: if `update` document has fields that don't start with `$` sign. This method only allows *modification* of document (with `$set`, `$inc`, etc.), not *replacing* it. For replacing use :meth:`replace_one()` instead. :param filter: A query that matches the documents to update. :param update: update document to be used for updating or upserting. See `MongoDB Update docs <https://docs.mongodb.org/manual/tutorial/modify-documents/>`_ for allowed operators. :param upsert: If ``True``, perform an insert if no documents match the `filter`. :returns: deferred instance of :class:`pymongo.results.UpdateResult`. """ validate_ok_for_update(update) raw_response = yield self._update(filter, update, upsert, multi=True, **kwargs) defer.returnValue(UpdateResult(raw_response, self.write_concern.acknowledged))
def add_update(self, selector: dict, update: dict, multi: bool = False, upsert: bool = False, collation=None) -> None: """Create an update document and add it to the list of ops. """ validate_ok_for_update(update) cmd = SON([('q', selector), ('u', update), ('multi', multi), ('upsert', upsert)]) self.ops.append((_UPDATE, cmd))
def add_update(self, selector, update, multi=False, upsert=False, collation=None): """Create an update document and add it to the list of ops. """ validate_ok_for_update(update) cmd = SON([('q', selector), ('u', update), ('multi', multi), ('upsert', upsert)]) collation = validate_collation_or_none(collation) if collation is not None: self.uses_collation = True cmd['collation'] = collation self.ops.append((_UPDATE, cmd))
def find_one_and_update(self, filter, update, projection=None, sort=None, upsert=False, return_document=ReturnDocument.BEFORE, **kwargs): validate_ok_for_update(update) result = yield self._new_find_and_modify(filter, projection, sort, upsert, return_document, update=update, **kwargs) defer.returnValue(result)
def add_update(self, selector, update, multi=False, upsert=False, collation=None, array_filters=None): """Create an update document and add it to the list of ops. """ validate_ok_for_update(update) cmd = SON([('q', selector), ('u', update), ('multi', multi), ('upsert', upsert)]) collation = validate_collation_or_none(collation) if collation is not None: self.uses_collation = True cmd['collation'] = collation if array_filters is not None: self.uses_array_filters = True cmd['arrayFilters'] = array_filters if multi: # A bulk_write containing an update_many is not retryable. self.is_retryable = False self.ops.append((_UPDATE, cmd))
def find_one_and_update(self, filter, update, projection=None, sort=None, upsert=False, return_document=ReturnDocument.BEFORE, array_filters=None, hint=None, session=None, **kwargs): common.validate_ok_for_update(update) common.validate_list_or_none('array_filters', array_filters) kwargs['update'] = update return self.__find_and_modify(filter, projection, sort, upsert, return_document, array_filters, hint=hint, session=session, **kwargs)
def find_one_and_update( self, filter, update, projection=None, sort=None, upsert=False, return_document=ReturnDocument.BEFORE, **kwargs ): validate_ok_for_update(update) return self._new_find_and_modify(filter, projection, sort, upsert, return_document, update=update, **kwargs)
def update_many(self, filter, update, upsert=False): validate_ok_for_update(update) raw_response = yield self._update(filter, update, upsert, multi=True) defer.returnValue(UpdateResult(raw_response, self.write_concern.acknowledged))
def update_many(self, filter, update, upsert=False, **kwargs): validate_ok_for_update(update) raw_response = yield self._update(filter, update, upsert, multi=True, **kwargs) defer.returnValue(UpdateResult(raw_response, self.write_concern.acknowledged))