@Experimental public class MongoDbIO extends java.lang.Object
MongoDbIO source returns a bounded collection of String as PCollection<String>
.
The String is the JSON form of the MongoDB Document.
To configure the MongoDB source, you have to provide the connection URI, the database name and the collection name. The following example illustrates various options for configuring the source:
pipeline.apply(MongoDbIO.read()
.withUri("mongodb://localhost:27017")
.withDatabase("my-database")
.withCollection("my-collection"))
// above three are required configuration, returns PCollection<String>
// rest of the settings are optional
The source also accepts an optional configuration: withFilter()
allows you to
define a JSON filter to get subset of data.
MongoDB sink supports writing of Document (as JSON String) in a MongoDB.
To configure a MongoDB sink, you must specify a connection URI
, a Database
name, a Collection
name. For instance:
pipeline
.apply(...)
.apply(MongoDbIO.write()
.withUri("mongodb://localhost:27017")
.withDatabase("my-database")
.withCollection("my-collection")
.withNumSplits(30))
Modifier and Type | Class and Description |
---|---|
static class |
MongoDbIO.Read
A
PTransform to read data from MongoDB. |
static class |
MongoDbIO.Write
A
PTransform to write to a MongoDB database. |
Modifier and Type | Method and Description |
---|---|
static MongoDbIO.Read |
read()
Read data from MongoDB.
|
static MongoDbIO.Write |
write()
Write data to MongoDB.
|
public static MongoDbIO.Read read()
public static MongoDbIO.Write write()