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

Method update_many

pymongo/asynchronous/collection.py:1354–1453  ·  view source on GitHub ↗

Update one or more documents that match the filter. >>> async for doc in db.test.find(): ... print(doc) ... {'x': 1, '_id': 0} {'x': 1, '_id': 1} {'x': 1, '_id': 2} >>> result = await db.test.update_many({'x': 1}, {'$inc': {'

(
        self,
        filter: Mapping[str, Any],
        update: Union[Mapping[str, Any], _Pipeline],
        upsert: bool = False,
        array_filters: Optional[Sequence[Mapping[str, Any]]] = None,
        bypass_document_validation: Optional[bool] = None,
        collation: Optional[_CollationIn] = None,
        hint: Optional[_IndexKeyHint] = None,
        session: Optional[AsyncClientSession] = None,
        let: Optional[Mapping[str, Any]] = None,
        comment: Optional[Any] = None,
    )

Source from the content-addressed store, hash-verified

1352 )
1353
1354 async def update_many(
1355 self,
1356 filter: Mapping[str, Any],
1357 update: Union[Mapping[str, Any], _Pipeline],
1358 upsert: bool = False,
1359 array_filters: Optional[Sequence[Mapping[str, Any]]] = None,
1360 bypass_document_validation: Optional[bool] = None,
1361 collation: Optional[_CollationIn] = None,
1362 hint: Optional[_IndexKeyHint] = None,
1363 session: Optional[AsyncClientSession] = None,
1364 let: Optional[Mapping[str, Any]] = None,
1365 comment: Optional[Any] = None,
1366 ) -> UpdateResult:
1367 """Update one or more documents that match the filter.
1368
1369 >>> async for doc in db.test.find():
1370 ... print(doc)
1371 ...
1372 {'x': 1, '_id': 0}
1373 {'x': 1, '_id': 1}
1374 {'x': 1, '_id': 2}
1375 >>> result = await db.test.update_many({'x': 1}, {'$inc': {'x': 3}})
1376 >>> result.matched_count
1377 3
1378 >>> result.modified_count
1379 3
1380 >>> async for doc in db.test.find():
1381 ... print(doc)
1382 ...
1383 {'x': 4, '_id': 0}
1384 {'x': 4, '_id': 1}
1385 {'x': 4, '_id': 2}
1386
1387 :param filter: A query that matches the documents to update.
1388 :param update: The modifications to apply.
1389 :param upsert: If ``True``, perform an insert if no documents
1390 match the filter.
1391 :param bypass_document_validation: If ``True``, allows the
1392 write to opt-out of document level validation. Default is
1393 ``False``.
1394 :param collation: An instance of
1395 :class:`~pymongo.collation.Collation`.
1396 :param array_filters: A list of filters specifying which
1397 array elements an update should apply.
1398 :param hint: An index to use to support the query
1399 predicate specified either by its string name, or in the same
1400 format as passed to
1401 :meth:`~pymongo.asynchronous.collection.AsyncCollection.create_index` (e.g.
1402 ``[('field', ASCENDING)]``). This option is only supported on
1403 MongoDB 4.2 and above.
1404 :param session: a
1405 :class:`~pymongo.asynchronous.client_session.AsyncClientSession`.
1406 :param let: Map of parameter names and values. Values must be
1407 constant or closed expressions that do not reference document
1408 fields. Parameters can then be accessed as variables in an
1409 aggregate expression context (e.g. "$$var").
1410 :param comment: A user-provided comment to attach to this
1411 command.

Callers

nothing calls this directly

Calls 3

_update_retryableMethod · 0.95
UpdateResultClass · 0.90
_write_concern_forMethod · 0.80

Tested by

no test coverage detected