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
260260 the ``movies`` collection in the ``sample_mflix`` database:
261261
262262 .. literalinclude:: /includes/get-started/quickstart.cpp
263+ :language: cpp
264+ :dedent:
263265
264266 .. step:: Assign the connection string
265267
@@ -306,9 +308,9 @@ Run a Sample Query
306308 "title" : "The Shawshank Redemption",
307309 ...
308310
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.
312314
313315After you complete these steps, you have a working application that
314316uses 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() {
1919 auto collection = db[" movies" ];
2020
2121 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+ }
2427}
Original file line number Diff line number Diff line change @@ -25,7 +25,11 @@ int main() {
2525 // Retrieves and prints one document that has a "name" value of "LinkedIn"
2626 // start-find-one
2727 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+ }
2933 // end-find-one
3034
3135 // 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() {
2323 // Retrieves one document that matches a query filter
2424 // start-find-one
2525 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+ }
2731 // end-find-one
2832 }
2933
You can’t perform that action at this time.
0 commit comments