MongoDbIO { public static Write write() { return new AutoValue_MongoDbIO_Write.Builder() .setMaxConnectionIdleTime(60000) .setBatchSize(1024L) .setSslEnabled(false) .setIgnoreSSLCertificate(false) .setSslInvalidHostNameAllowed(false) .setOrdered(true) .build(); } private  MongoDbIO(); static Read read(); static Write write();  }
@Test public void testWrite() { final String collectionName = "testWrite"; final int numElements = 1000; pipeline .apply(Create.of(createDocuments(numElements))) .apply( MongoDbIO.write() .withUri("mongodb: .withDatabase(DATABASE) .withCollection(collectionName)); pipeline.run(); assertEquals(numElements, countElements(collectionName)); }
@Test public void testWriteUnordered() { final String collectionName = "testWriteUnordered"; Document doc = Document.parse("{\"_id\":\"521df3a4300466f1f2b5ae82\",\"scientist\":\"Test %s\"}"); pipeline .apply(Create.of(doc, doc)) .apply( MongoDbIO.write() .withUri("mongodb: .withDatabase(DATABASE) .withOrdered(false) .withCollection(collectionName)); pipeline.run(); assertEquals(1, countElements(collectionName)); }