Writes ``table`` to a MongoDB table. The output table supports two formats, controlled by the ``output_table_type`` parameter. The ``stream_of_changes`` format provides a complete history of all modifications applied to the table. Each entry contains the full data row along with tw
(
table: Table,
*,
connection_string: str,
database: str,
collection: str,
output_table_type: Literal["stream_of_changes", "snapshot"] = "stream_of_changes",
max_batch_size: int | None = None,
name: str | None = None,
sort_by: Iterable[ColumnReference] | None = None,
)
| 319 | @check_arg_types |
| 320 | @trace_user_frame |
| 321 | def write( |
| 322 | table: Table, |
| 323 | *, |
| 324 | connection_string: str, |
| 325 | database: str, |
| 326 | collection: str, |
| 327 | output_table_type: Literal["stream_of_changes", "snapshot"] = "stream_of_changes", |
| 328 | max_batch_size: int | None = None, |
| 329 | name: str | None = None, |
| 330 | sort_by: Iterable[ColumnReference] | None = None, |
| 331 | ) -> None: |
| 332 | """Writes ``table`` to a MongoDB table. |
| 333 | |
| 334 | The output table supports two formats, controlled by the ``output_table_type`` |
| 335 | parameter. |
| 336 | |
| 337 | The ``stream_of_changes`` format provides a complete history of all modifications |
| 338 | applied to the table. Each entry contains the full data row along with two |
| 339 | additional fields: ``time`` and ``diff``. The ``time`` field identifies the |
| 340 | transactional minibatch in which the change occurred, while ``diff`` describes |
| 341 | the nature of the change: ``diff = 1`` indicates that the row was inserted into |
| 342 | the Pathway Live Data Framework table, and ``diff = -1`` indicates that the row was removed. Row |
| 343 | updates are represented as two events within the same transactional minibatch: |
| 344 | first the old version of the row with ``diff = -1``, followed by the new version |
| 345 | with ``diff = 1``. This format is used by default. Because ``time`` and ``diff`` |
| 346 | are reserved field names in this format, the input table must not contain columns |
| 347 | with these names; otherwise a ``ValueError`` is raised at construction time. |
| 348 | |
| 349 | The ``snapshot`` format maintains the current state of the Pathway Live Data Framework table in the |
| 350 | output. The table's primary key is stored in the ``_id`` field. When a change |
| 351 | occurs, no additional metadata fields are added; instead, the engine locates the |
| 352 | corresponding row by ``_id`` and applies the update directly. As a result, the |
| 353 | output table always reflects the latest state of the Pathway Live Data Framework table. |
| 354 | |
| 355 | **Reserved column name**: in both formats, the input table must not contain a |
| 356 | column named ``_id`` — MongoDB uses ``_id`` as the primary key for every |
| 357 | document. A ``ValueError`` is raised at construction time if this column is |
| 358 | present. |
| 359 | |
| 360 | If the specified database or table doesn't exist, it will be created during the |
| 361 | first write. |
| 362 | |
| 363 | **Note:** Since MongoDB |
| 364 | `stores DateTime in milliseconds <https://www.mongodb.com/docs/manual/reference/bson-types/#date>`_, |
| 365 | the `Duration </developers/api-docs/pathway/#pathway.Duration>`_ type is also |
| 366 | serialized as an integer number of milliseconds for consistency. |
| 367 | |
| 368 | Args: |
| 369 | table: The table to output. |
| 370 | connection_string: The connection string for the MongoDB database. See the \ |
| 371 | `MongoDB documentation <https://www.mongodb.com/docs/manual/reference/connection-string/>`_ \ |
| 372 | for the details. |
| 373 | database: The name of the database to update. |
| 374 | collection: The name of the collection to write to. |
| 375 | output_table_type: The type of the output table, defining whether a current snapshot |
| 376 | or a history of modifications must be maintained. |
| 377 | max_batch_size: The maximum number of entries to insert in one batch. |
| 378 | name: A unique name for the connector. If provided, this name will be used in |
nothing calls this directly
no test coverage detected