File tree Expand file tree Collapse file tree 4 files changed +20
-7
lines changed Expand file tree Collapse file tree 4 files changed +20
-7
lines changed Original file line number Diff line number Diff line change @@ -260,6 +260,8 @@ Run a Sample Query
260
260
the ``movies`` collection in the ``sample_mflix`` database:
261
261
262
262
.. literalinclude:: /includes/get-started/quickstart.cpp
263
+ :language: cpp
264
+ :dedent:
263
265
264
266
.. step:: Assign the connection string
265
267
@@ -306,9 +308,9 @@ Run a Sample Query
306
308
"title" : "The Shawshank Redemption",
307
309
...
308
310
309
- If you encounter an error or see no output, ensure that you specified the
310
- proper connection string in the ``quickstart.cpp`` file and that you loaded the
311
- sample data.
311
+ If you encounter an error or if your application prints ``"No result found"``,
312
+ ensure that you specified the proper connection string in the ``quickstart.cpp``
313
+ file and that you loaded the sample data.
312
314
313
315
After you complete these steps, you have a working application that
314
316
uses the driver to connect to your MongoDB deployment, runs a query on
Original file line number Diff line number Diff line change @@ -19,6 +19,9 @@ int main() {
19
19
auto collection = db[" movies" ];
20
20
21
21
auto result = collection.find_one (make_document (kvp (" title" , " The Shawshank Redemption" )));
22
- std::cout << bsoncxx::to_json (*result) << std::endl;
23
-
22
+ if (result) {
23
+ std::cout << bsoncxx::to_json (*result) << std::endl;
24
+ } else {
25
+ std::cout << " No result found" << std::endl;
26
+ }
24
27
}
Original file line number Diff line number Diff line change @@ -25,7 +25,11 @@ int main() {
25
25
// Retrieves and prints one document that has a "name" value of "LinkedIn"
26
26
// start-find-one
27
27
auto result = collection.find_one (make_document (kvp (" name" , " LinkedIn" )));
28
- std::cout << bsoncxx::to_json (*result) << std::endl;
28
+ if (result) {
29
+ std::cout << bsoncxx::to_json (*result) << std::endl;
30
+ } else {
31
+ std::cout << " No result found" << std::endl;
32
+ }
29
33
// end-find-one
30
34
31
35
// Retrieves documents that have a "founded_year" value of 1970
Original file line number Diff line number Diff line change @@ -23,7 +23,11 @@ int main() {
23
23
// Retrieves one document that matches a query filter
24
24
// start-find-one
25
25
auto result = collection.find_one (make_document (kvp (" <field name>" , " <value>" )));
26
- std::cout << bsoncxx::to_json (*result) << std::endl;
26
+ if (result) {
27
+ std::cout << bsoncxx::to_json (*result) << std::endl;
28
+ } else {
29
+ std::cout << " No result found" << std::endl;
30
+ }
27
31
// end-find-one
28
32
}
29
33
You can’t perform that action at this time.
0 commit comments