-
Type: Task
-
Resolution: Done
-
Priority: Major - P3
-
None
-
Component/s: None
-
None
Hi,
I'd be great if we had equivalent code samples to the JAVA code that's featured on the MongoDB 3.6 page (linked from the mongodb.com page) for a few different features.
The url is https://www.mongodb.com/mongodb-3.6
Change Streams:
// 1. The database for reactive, real-time applications MongoClient mongoClient; // Create a new MongoClient with a MongoDB URI string. if (args.length == 0) { // Defaults to a localhost replicaset on ports: 27017, 27018, 27019 mongoClient = new MongoClient(new MongoClientURI("mongodb://localhost:27017,localhost:27018,localhost:27019")); } else { mongoClient = new MongoClient(new MongoClientURI(args[0])); } // Select the MongoDB database. MongoDatabase database = mongoClient.getDatabase("testChangeStreams"); // Select the collection to query. MongoCollection<Document> collection = database.getCollection("documents"); // Create the change stream cursor. MongoCursor<Document> cursor = collection.watch().iterator();
Causal Consistency
// 2. Tunable consistency controls String connectionString = "mongodb://localhost/?readPreference=secondaryPreferred"; MongoClient client = new MongoClient(new MongoClientURI(connectionString); MongoDatabase database = client.getDatabase("myDatabase"); MongoCollection<Document> collection = database.getCollection("myCollection"); // Start client session, which is causally consistent by default try (ClientSession session = client.startSession(ClientSessionOptions.builder().build())) { //Run causally related operations within the session collection.insertOne(session, ...); collection.updateOne(session, ...); try (MongoCursor<Document> cursor = collection.find(session).filter(...).iterator()) { while (cursor.hasNext()) { Document cur = cursor.next(); } } }
Array Updates
// 3. Exploiting the power of arrays MongoCollection<Document> collection = client .getDatabase("test") .getCollection("arrayUpdatesTest"); collection.updateOne( Filters.eq("_id", 1), Updates.set("a.$[i].b", 2), new UpdateOptions() .arrayFilters( Collections.singletonList( Filters.eq("i.b", 0))));
- depends on
-
CSHARP-2141 Create Causal Consistency code samples for MongoDB 3.6 page
- Closed
-
CSHARP-2142 Create Array update code samples for MongoDB 3.6 page
- Closed
-
CXX-1450 ChangeStreams Examples for Docs
- Closed
-
CXX-1490 Create Causal Consistency code samples for MongoDB 3.6 page
- Closed
-
CXX-1491 Create Array update code samples for MongoDB 3.6 page
- Closed
-
JAVA-2726 Create Causal Consistency code samples for MongoDB 3.6 page
- Closed
-
JAVA-2727 Create Array update code samples for MongoDB 3.6 page
- Closed
-
NODE-1262 Create Causal Consistency code samples for MongoDB 3.6 page
- Closed
-
NODE-1263 Create Array update code samples for MongoDB 3.6 page
- Closed
-
PYTHON-1445 Create Causal Consistency code samples for MongoDB 3.6 page
- Closed
-
PYTHON-1446 Create Array update code samples for MongoDB 3.6 page
- Closed
- related to
-
DRIVERS-436 Add pipeline stage to ChangeStreams example for Docs
- Closed