MCPcopy Index your code
hub / github.com/mongodb/mongo-python-driver / __init__

Method __init__

pymongo/operations.py:331–385  ·  view source on GitHub ↗

Create a ReplaceOne instance. For use with :meth:`~pymongo.asynchronous.collection.AsyncCollection.bulk_write`, :meth:`~pymongo.collection.Collection.bulk_write`, :meth:`~pymongo.asynchronous.mongo_client.AsyncMongoClient.bulk_write` and :meth:`~pymongo.mongo_client.MongoClient.bulk

(
        self,
        filter: Mapping[str, Any],
        replacement: Union[_DocumentType, RawBSONDocument],
        upsert: Optional[bool] = None,
        collation: Optional[_CollationIn] = None,
        hint: Optional[_IndexKeyHint] = None,
        namespace: Optional[str] = None,
        sort: Optional[Mapping[str, Any]] = None,
    )

Source from the content-addressed store, hash-verified

329 )
330
331 def __init__(
332 self,
333 filter: Mapping[str, Any],
334 replacement: Union[_DocumentType, RawBSONDocument],
335 upsert: Optional[bool] = None,
336 collation: Optional[_CollationIn] = None,
337 hint: Optional[_IndexKeyHint] = None,
338 namespace: Optional[str] = None,
339 sort: Optional[Mapping[str, Any]] = None,
340 ) -> None:
341 """Create a ReplaceOne instance.
342
343 For use with :meth:`~pymongo.asynchronous.collection.AsyncCollection.bulk_write`, :meth:`~pymongo.collection.Collection.bulk_write`,
344 :meth:`~pymongo.asynchronous.mongo_client.AsyncMongoClient.bulk_write` and :meth:`~pymongo.mongo_client.MongoClient.bulk_write`.
345
346 :param filter: A query that matches the document to replace.
347 :param replacement: The new document.
348 :param upsert: If ``True``, perform an insert if no documents
349 match the filter.
350 :param collation: An instance of
351 :class:`~pymongo.collation.Collation`.
352 :param hint: An index to use to support the query
353 predicate specified either by its string name, or in the same
354 format as passed to
355 :meth:`~pymongo.asynchronous.collection.AsyncCollection.create_index` or :meth:`~pymongo.collection.Collection.create_index` (e.g.
356 ``[('field', ASCENDING)]``). This option is only supported on
357 MongoDB 4.2 and above.
358 :param sort: Specify which document the operation updates if the query matches
359 multiple documents. The first document matched by the sort order will be updated.
360 :param namespace: (optional) The namespace in which to replace a document.
361
362 .. versionchanged:: 4.10
363 Added ``sort`` option.
364 .. versionchanged:: 4.9
365 Added the `namespace` option to support `MongoClient.bulk_write`.
366 .. versionchanged:: 3.11
367 Added the ``hint`` option.
368 .. versionchanged:: 3.5
369 Added the ``collation`` option.
370 """
371 if filter is not None:
372 validate_is_mapping("filter", filter)
373 if upsert is not None:
374 validate_boolean("upsert", upsert)
375 if hint is not None and not isinstance(hint, str):
376 self._hint: Union[str, dict[str, Any], None] = helpers_shared._index_document(hint)
377 else:
378 self._hint = hint
379
380 self._sort = sort
381 self._filter = filter
382 self._doc = replacement
383 self._upsert = upsert
384 self._collation = collation
385 self._namespace = namespace
386
387 def _add_to_bulk(self, bulkobj: _AgnosticBulk) -> None:
388 """Add this operation to the _AsyncBulk/_Bulk instance `bulkobj`."""

Callers

nothing calls this directly

Calls 2

validate_is_mappingFunction · 0.90
validate_booleanFunction · 0.90

Tested by

no test coverage detected