Skip to content

Commit

Permalink
wording, fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
norareidy committed Jun 24, 2024
1 parent c7ce424 commit df8367d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
2 changes: 1 addition & 1 deletion source/includes/read/retrieve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ int main() {
// start-cursor
auto cursor = collection.find(make_document(kvp("founded_year", 1970)));
for(auto&& doc : cursor) {
std::cout << bsoncxx::to_json(doc) << std::endl;
std::cout << bsoncxx::to_json(doc) << "\n" << std::endl;
}
// end-cursor

Expand Down
42 changes: 29 additions & 13 deletions source/read/retrieve.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,18 @@ Retrieve Data
Overview
--------

In this guide, you can learn how to use {+driver-short+} to retrieve
data from a MongoDB collection by using read operations. You can call the
In this guide, you can learn how to use the {+driver-short+} to retrieve
data from a MongoDB collection by using **read operations**. You can call the
``find()`` or ``find_one()`` method on a collection to retrieve documents
that match a set of criteria.

Sample Data
~~~~~~~~~~~

The examples in this guide use the ``companies`` collection in the ``sample_training``
database from the :atlas:`Atlas sample datasets </sample-data>`. Use the following code to
access this collection from your C++ application:
database from the :atlas:`Atlas sample datasets </sample-data>`. To access this collection
from your C++ application, instantiate a ``client`` that connects to an Atlas cluster
and assign the following values to your ``db`` and ``collection`` variables:

.. literalinclude:: /includes/read/retrieve.cpp
:language: cpp
Expand Down Expand Up @@ -120,11 +121,26 @@ amount of documents.
You can iterate over the documents in a cursor by using a ``for-in`` loop, as shown in
the following example:

.. literalinclude:: /includes/read/retrieve.cpp
:language: cpp
:dedent:
:start-after: start-cursor
:end-before: end-cursor
.. io-code-block::

.. input:: /includes/read/retrieve.cpp
:start-after: start-cursor
:end-before: end-cursor
:language: cpp

.. output::

{ "_id" : { "$oid" : "52cdef7d4bab8bd675298be4" }, "name" : "Mitsubishi Motors",
"permalink" : "mitsubishi-motors", "crunchbase_url" : "http://www.crunchbase.com/company/mitsubishi-motors",
...

{ "_id" : { "$oid" : "52cdef7e4bab8bd67529b996" }, "name" : "Western Digital",
"permalink" : "western-digital", "crunchbase_url" : "http://www.crunchbase.com/company/western-digital",
...

{ "_id" : { "$oid" : "52cdef7e4bab8bd67529b9f1" }, "name" : "Celarayn", "permalink" : "celarayn",
"crunchbase_url" : "http://www.crunchbase.com/company/celarayn",
...

.. note:: Find All Documents

Expand Down Expand Up @@ -177,9 +193,9 @@ describes some of the fields you can set in a ``mongocxx::options::find`` instan
- | The order in which the operation returns matching documents.
| Type: ``bsoncxx::document::view_or_value``

The following example uses the ``find()`` method to find all documents where
the ``number_of_employees`` field has the value greater than ``1000`` and instructs
the operation to return a maximum of five results:
The following example uses the ``find()`` method to find all documents in which
the ``number_of_employees`` field has the value ``1000`` and instructs the
operation to return a maximum of five results:

.. literalinclude:: /includes/read/retrieve.cpp
:language: cpp
Expand All @@ -188,7 +204,7 @@ the operation to return a maximum of five results:
:end-before: end-modify

For a full list of ``mongocxx::options::find`` object fields, see the
`API documentation <{+api+}/classmongocxx_1_1options_1_1find.html>`__.
`API documentation <{+api+}/classmongocxx_1_1v__noabi_1_1options_1_1find.html>`__.

.. _cpp-retrieve-additional-information:

Expand Down

0 comments on commit df8367d

Please sign in to comment.