class ray.data.datasource.MongoDatasource[source]#

Bases: ray.data.datasource.datasource.Datasource

Datasource for reading from and writing to MongoDB.


>>> import ray
>>> from ray.data.datasource import MongoDatasource
>>> from pymongoarrow.api import Schema 
>>> ds = ray.data.read_datasource( 
...     MongoDatasource(), 
...     uri="mongodb://username:password@mongodb0.example.com:27017/?authSource=admin", # noqa: E501 
...     database="my_db", 
...     collection="my_collection", 
...     schema=Schema({"col1": pa.string(), "col2": pa.int64()}), 
... ) 

PublicAPI (alpha): This API is in alpha and may change before becoming stable.



do_write(blocks, metadata, ray_remote_args, ...)

Launch Ray tasks for writing blocks out to the datasource.


Return a human-readable name for this datasource.

on_write_complete(write_results, **kwargs)

Callback for when a write job completes.

on_write_failed(write_results, error, **kwargs)

Callback for when a write job fails.

prepare_read(parallelism, **read_args)

Deprecated: Please implement create_reader() instead.