Skip to content

Commit 757e26d

Browse files
author
Chris Cho
authored
DOCSP-26555: update quickstart (#311)
* DOCSP-26555: update quickstart
1 parent 383feb4 commit 757e26d

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

source/includes/quick-start/code-snippets/QuickStart.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,23 @@
1010
import com.mongodb.client.MongoCollection;
1111
import com.mongodb.client.MongoDatabase;
1212

13-
public static void main( String[] args ) {
13+
public class QuickStart {
14+
public static void main( String[] args ) {
1415

15-
// Replace the uri string with your MongoDB deployment's connection string
16-
String uri = "<connection string uri>";
16+
// Replace the placeholder with your MongoDB deployment's connection string
17+
String uri = "<connection string uri>";
1718

18-
try (MongoClient mongoClient = MongoClients.create(uri)) {
19-
MongoDatabase database = mongoClient.getDatabase("sample_mflix");
20-
MongoCollection<Document> collection = database.getCollection("movies");
19+
try (MongoClient mongoClient = MongoClients.create(uri)) {
20+
MongoDatabase database = mongoClient.getDatabase("sample_mflix");
21+
MongoCollection<Document> collection = database.getCollection("movies");
2122

22-
Document doc = collection.find(eq("title", "Back to the Future")).first();
23-
System.out.println(doc.toJson());
23+
Document doc = collection.find(eq("title", "Back to the Future")).first();
24+
if (doc != null) {
25+
System.out.println(doc.toJson());
26+
} else {
27+
System.out.println("No matching documents found.");
28+
}
29+
}
2430
}
2531
}
2632
// end QuickStart

source/quick-start.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ Next, create a file to contain your application called ``QuickStart.java``
6262
in the base package directory of your project. Use the following sample
6363
code to run a query on your sample dataset in MongoDB Atlas, replacing the
6464
value of the ``uri`` variable with your MongoDB Atlas connection string.
65-
Ensure you replace the "<password>" section of the connection string with
66-
the password you created for your user that has **atlasAdmin** permissions:
6765

6866
.. literalinclude:: /includes/quick-start/code-snippets/QuickStart.java
6967
:start-after: begin QuickStart

0 commit comments

Comments
 (0)