Example #1
0
 def add_replace(self, selector, replacement, upsert=False):
     """Create a replace document and add it to the list of ops.
     """
     validate_ok_for_replace(replacement)
     cmd = SON([('q', selector), ('u', replacement), ('multi', False),
                ('upsert', upsert)])
     self.ops.append((_UPDATE, cmd))
Example #2
0
 def add_replace(self, selector, replacement, upsert=False):
     """Create a replace document and add it to the list of ops.
     """
     validate_ok_for_replace(replacement)
     cmd = SON([('q', selector), ('u', replacement),
                ('multi', False), ('upsert', upsert)])
     self.ops.append((_UPDATE, cmd))
Example #3
0
    def replace_one(self, filter, replacement, upsert=False, **kwargs):
        """Replace a single document matching the filter.

        :raises ValueError:
            if `update` document is empty

        :raises ValueError:
            if `update` document has fields that starts with `$` sign.
            This method only allows *replacing* document completely. Use
            :meth:`update_one()` for modifying existing document.

        :param filter:
            A query that matches the document to replace.

        :param replacement:
            The new document to replace with.

        :param upsert:
            If ``True``, perform an insert if no documents match the filter.

        :returns:
            deferred instance of :class:`pymongo.results.UpdateResult`.
        """
        validate_ok_for_replace(replacement)

        raw_response = yield self._update(filter,
                                          replacement,
                                          upsert,
                                          multi=False,
                                          **kwargs)
        defer.returnValue(
            UpdateResult(raw_response, self.write_concern.acknowledged))
Example #4
0
    def replace_one(self, filter, replacement, upsert=False, **kwargs):
        """Replace a single document matching the filter.

        :raises ValueError:
            if `update` document is empty

        :raises ValueError:
            if `update` document has fields that starts with `$` sign.
            This method only allows *replacing* document completely. Use
            :meth:`update_one()` for modifying existing document.

        :param filter:
            A query that matches the document to replace.

        :param replacement:
            The new document to replace with.

        :param upsert:
            If ``True``, perform an insert if no documents match the filter.

        :returns:
            deferred instance of :class:`pymongo.results.UpdateResult`.
        """
        validate_ok_for_replace(replacement)

        raw_response = yield self._update(filter, replacement, upsert, multi=False, **kwargs)
        defer.returnValue(UpdateResult(raw_response, self.write_concern.acknowledged))
Example #5
0
 def add_replace(self, selector, replacement, upsert=False, collation=None):
     """Create a replace document and add it to the list of ops.
     """
     validate_ok_for_replace(replacement)
     cmd = SON([('q', selector), ('u', replacement), ('multi', False),
                ('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))
Example #6
0
 def add_replace(self,
                 selector: dict,
                 replacement: dict,
                 upsert: bool = False,
                 collation=None) -> None:
     """Create a replace document and add it to the list of ops.
     """
     validate_ok_for_replace(replacement)
     cmd = SON([('q', selector), ('u', replacement), ('multi', False),
                ('upsert', upsert)])
     self.ops.append((_UPDATE, cmd))
Example #7
0
 def add_replace(self, selector, replacement, upsert=False,
                 collation=None):
     """Create a replace document and add it to the list of ops.
     """
     validate_ok_for_replace(replacement)
     cmd = SON([('q', selector), ('u', replacement),
                ('multi', False), ('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))
Example #8
0
 def find_one_and_replace(
     self,
     filter,
     replacement,
     projection=None,
     sort=None,
     upsert=False,
     return_document=ReturnDocument.BEFORE,
     **kwargs
 ):
     validate_ok_for_replace(replacement)
     return self._new_find_and_modify(
         filter, projection, sort, upsert, return_document, update=replacement, **kwargs
     )
Example #9
0
 def find_one_and_replace(self,
                          filter,
                          replacement,
                          projection=None,
                          sort=None,
                          upsert=False,
                          return_document=ReturnDocument.BEFORE,
                          **kwargs):
     validate_ok_for_replace(replacement)
     result = yield self._new_find_and_modify(filter,
                                              projection,
                                              sort,
                                              upsert,
                                              return_document,
                                              update=replacement,
                                              **kwargs)
     defer.returnValue(result)
Example #10
0
 def add_replace(self,
                 selector,
                 replacement,
                 upsert=False,
                 collation=None,
                 hint=None):
     """Create a replace document and add it to the list of ops."""
     validate_ok_for_replace(replacement)
     cmd = SON([("q", selector), ("u", replacement), ("multi", False),
                ("upsert", upsert)])
     collation = validate_collation_or_none(collation)
     if collation is not None:
         self.uses_collation = True
         cmd["collation"] = collation
     if hint is not None:
         self.uses_hint_update = True
         cmd["hint"] = hint
     self.ops.append((_UPDATE, cmd))
Example #11
0
    def replace_one(self, filter, replacement, upsert=False):
        validate_ok_for_replace(replacement)

        raw_response = yield self._update(filter, replacement, upsert, multi=False)
        defer.returnValue(UpdateResult(raw_response, self.write_concern.acknowledged))
Example #12
0
    def replace_one(self, filter, replacement, upsert=False, **kwargs):
        validate_ok_for_replace(replacement)

        raw_response = yield self._update(filter, replacement, upsert, multi=False, **kwargs)
        defer.returnValue(UpdateResult(raw_response, self.write_concern.acknowledged))