Skip to content

Commit 85b27b8

Browse files
committed
JS feedback
1 parent 2a2536f commit 85b27b8

File tree

2 files changed

+44
-8
lines changed

2 files changed

+44
-8
lines changed

source/crud/transactions.txt

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ Causal Consistency
5555

5656
MongoDB enables **causal consistency** in client sessions.
5757
The causal consistency model guarantees that operations within a session
58-
run in a causal order. Additionally, clients observe results that
59-
are consistent with the causal relationships, or the dependencies between
60-
operations. If you perform a series of operations where one operation
61-
logically depends on the result of another, any subsequent
58+
run in a causal order. Clients observe results that are consistent
59+
with the causal relationships, or the dependencies between
60+
operations. For example, if you perform a series of operations where
61+
one operation logically depends on the result of another, any subsequent
6262
reads reflect the dependent relationship.
6363

6464
The following table describes the guarantees that causally
@@ -79,12 +79,20 @@ consistent sessions provide:
7979
a preceding read operation.
8080

8181
* - Monotonic writes
82-
- The driver runs write operations that logically must precede other write operations
83-
before these dependent writes.
82+
- If a write operation must precede other write operations, the driver
83+
runs this write operation first.
84+
85+
For example, if you call ``insertOne()`` to insert a document, then call
86+
``updateOne()`` to modify the inserted document, the driver runs the
87+
insert operation first.
8488

8589
* - Writes follow reads
86-
- The driver runs write operations that logically must follow other read operations
87-
after these reads.
90+
- If a write operation must follow other read operations, the driver runs
91+
the read operations first.
92+
93+
For example, if you call ``find()`` to retrieve a document, then call
94+
``deleteOne()`` to delete the retrieved document, the driver runs the find
95+
operation first.
8896

8997
In a causally consistent session, MongoDB ensures a
9098
causal relationship between the following operations:

source/includes/AtlasSearch.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package source.includes;
2+
3+
import org.bson.Document;
4+
5+
import com.mongodb.client.MongoClient;
6+
import com.mongodb.client.MongoClients;
7+
import com.mongodb.client.MongoCollection;
8+
import com.mongodb.client.MongoDatabase;
9+
10+
public class AtlasSearch {
11+
public static void main( String[] args ) {
12+
13+
// Replace the placeholder with your MongoDB deployment's connection string
14+
String uri = "<connection string uri>";
15+
16+
try (MongoClient mongoClient = MongoClients.create(uri)) {
17+
MongoDatabase database = mongoClient.getDatabase("sample_mflix");
18+
MongoCollection<Document> collection = database.getCollection("movies");
19+
20+
Document doc = collection.find(eq("title", "Back to the Future")).first();
21+
if (doc != null) {
22+
System.out.println(doc.toJson());
23+
} else {
24+
System.out.println("No matching documents found.");
25+
}
26+
}
27+
}
28+
}

0 commit comments

Comments
 (0)