Participer au site avec un Tip
Rechercher
 

Améliorations / Corrections

Vous avez des améliorations (ou des corrections) à proposer pour ce document : je vous remerçie par avance de m'en faire part, cela m'aide à améliorer le site.

Emplacement :

Description des améliorations :

Vous êtes un professionnel et vous avez besoin d'une formation ? Mise en oeuvre d'IHM
avec Qt et PySide6
Voir le programme détaillé
Classe « AsyncMongoClient »

Méthode pymongo.AsyncMongoClient.bulk_write

Signature de la méthode bulk_write

def bulk_write(self, models: 'Sequence[_WriteOp[_DocumentType]]', session: 'Optional[AsyncClientSession]' = None, ordered: 'bool' = True, verbose_results: 'bool' = False, bypass_document_validation: 'Optional[bool]' = None, comment: 'Optional[Any]' = None, let: 'Optional[Mapping]' = None, write_concern: 'Optional[WriteConcern]' = None) -> 'ClientBulkWriteResult' 

Description

help(AsyncMongoClient.bulk_write)

Send a batch of write operations, potentially across multiple namespaces, to the server.

Requests are passed as a list of write operation instances (
:class:`~pymongo.operations.InsertOne`,
:class:`~pymongo.operations.UpdateOne`,
:class:`~pymongo.operations.UpdateMany`,
:class:`~pymongo.operations.ReplaceOne`,
:class:`~pymongo.operations.DeleteOne`, or
:class:`~pymongo.operations.DeleteMany`).

  >>> async for doc in db.test.find({}):
  ...     print(doc)
  ...
  {'x': 1, '_id': ObjectId('54f62e60fba5226811f634ef')}
  {'x': 1, '_id': ObjectId('54f62e60fba5226811f634f0')}
  ...
  >>> async for doc in db.coll.find({}):
  ...     print(doc)
  ...
  {'x': 2, '_id': ObjectId('507f1f77bcf86cd799439011')}
  ...
  >>> # DeleteMany, UpdateOne, and UpdateMany are also available.
  >>> from pymongo import InsertOne, DeleteOne, ReplaceOne
  >>> models = [InsertOne(namespace="db.test", document={'y': 1}),
  ...           DeleteOne(namespace="db.test", filter={'x': 1}),
  ...           InsertOne(namespace="db.coll", document={'y': 2}),
  ...           ReplaceOne(namespace="db.test", filter={'w': 1}, replacement={'z': 1}, upsert=True)]
  >>> result = await client.bulk_write(models=models)
  >>> result.inserted_count
  2
  >>> result.deleted_count
  1
  >>> result.modified_count
  0
  >>> result.upserted_count
  1
  >>> async for doc in db.test.find({}):
  ...     print(doc)
  ...
  {'x': 1, '_id': ObjectId('54f62e60fba5226811f634f0')}
  {'y': 1, '_id': ObjectId('54f62ee2fba5226811f634f1')}
  {'z': 1, '_id': ObjectId('54f62ee28891e756a6e1abd5')}
  ...
  >>> async for doc in db.coll.find({}):
  ...     print(doc)
  ...
  {'x': 2, '_id': ObjectId('507f1f77bcf86cd799439011')}
  {'y': 2, '_id': ObjectId('507f1f77bcf86cd799439012')}

:param models: A list of write operation instances.
:param session: (optional) An instance of
    :class:`~pymongo.asynchronous.client_session.AsyncClientSession`.
:param ordered: If ``True`` (the default), requests will be
    performed on the server serially, in the order provided. If an error
    occurs all remaining operations are aborted. If ``False``, requests
    will be still performed on the server serially, in the order provided,
    but all operations will be attempted even if any errors occur.
:param verbose_results: If ``True``, detailed results for each
    successful operation will be included in the returned
    :class:`~pymongo.results.ClientBulkWriteResult`. Default is ``False``.
:param bypass_document_validation: (optional) If ``True``, allows the
    write to opt-out of document level validation. Default is ``False``.
:param comment: (optional) A user-provided comment to attach to this
    command.
:param let: (optional) Map of parameter names and values. Values must be
    constant or closed expressions that do not reference document
    fields. Parameters can then be accessed as variables in an
    aggregate expression context (e.g. "$$var").
:param write_concern: (optional) The write concern to use for this bulk write.

:return: An instance of :class:`~pymongo.results.ClientBulkWriteResult`.

.. seealso:: For more info, see :doc:`/examples/client_bulk`.

.. seealso:: :ref:`writes-and-ids`

.. note:: requires MongoDB server version 8.0+.

.. versionadded:: 4.9


Vous êtes un professionnel et vous avez besoin d'une formation ? Deep Learning avec Python
et Keras et Tensorflow
Voir le programme détaillé