コード例 #1
0
ファイル: bulk.py プロジェクト: Yucie/Arianrhod
 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))
コード例 #2
0
ファイル: bulk.py プロジェクト: RazoRTR/Arianrhod
 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))
コード例 #3
0
 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))
コード例 #4
0
    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))
コード例 #5
0
ファイル: collection.py プロジェクト: jdcumpson/txmongo
    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))
コード例 #6
0
ファイル: bulk.py プロジェクト: iceboy233/aiomongo
 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))
コード例 #7
0
ファイル: bulk.py プロジェクト: Joseph7117/Suggestion_Box
 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))
コード例 #8
0
 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))
コード例 #9
0
 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)
コード例 #10
0
ファイル: bulk.py プロジェクト: ZJDong/Wayfindr-Py
 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))
コード例 #11
0
    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)
コード例 #12
0
ファイル: collection.py プロジェクト: hawkowl/txmongo
 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)
コード例 #13
0
ファイル: collection.py プロジェクト: hawkowl/txmongo
    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))
コード例 #14
0
    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))