Skip to content

Commit 90f6ffa

Browse files
fgalankevinAlbs
andauthored
Improve docs of cursor returning functions (#740)
Co-authored-by: Kevin Albertson <[email protected]> Co-authored-by: Fermín Galán Márquez <[email protected]>
1 parent 0805656 commit 90f6ffa

11 files changed

+29
-23
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
This function returns a newly allocated :symbol:`mongoc_cursor_t` that should be freed with :symbol:`mongoc_cursor_destroy()` when no longer in use. The returned :symbol:`mongoc_cursor_t` is never ``NULL``, even on error. The user must call :symbol:`mongoc_cursor_next()` on the returned :symbol:`mongoc_cursor_t` to execute the initial command.
2+
3+
Cursor errors can be checked with :symbol:`mongoc_cursor_error_document`. It always fills out the :symbol:`bson_error_t` if an error occurred, and optionally includes a server reply document if the error occurred server-side.
4+
5+
.. warning::
6+
7+
Failure to handle the result of this function is a programming error.

src/libmongoc/doc/mongoc_collection_aggregate.rst

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,7 @@ Transaction Transaction Transaction
5454
Returns
5555
-------
5656

57-
This function returns a newly allocated :symbol:`mongoc_cursor_t` that should be freed with :symbol:`mongoc_cursor_destroy()` when no longer in use. The returned :symbol:`mongoc_cursor_t` is never ``NULL``; if the parameters are invalid, the :symbol:`bson:bson_error_t` in the :symbol:`mongoc_cursor_t` is filled out, and the :symbol:`mongoc_cursor_t` is returned before the server is selected. The user must call :symbol:`mongoc_cursor_next()` on the returned :symbol:`mongoc_cursor_t` to execute the aggregation pipeline.
58-
59-
.. warning::
60-
61-
Failure to handle the result of this function is a programming error.
57+
.. include:: includes/returns-cursor.txt
6258

6359
Example
6460
-------

src/libmongoc/doc/mongoc_collection_command.rst

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,4 @@ Parameters
3838
Returns
3939
-------
4040

41-
A :symbol:`mongoc_cursor_t`.
42-
43-
The cursor should be freed with :symbol:`mongoc_cursor_destroy()`.
44-
41+
.. include:: includes/returns-cursor.txt

src/libmongoc/doc/mongoc_collection_find.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ If no options are necessary, ``query`` can simply contain a query such as ``{a:1
5151
Returns
5252
-------
5353

54-
A newly allocated :symbol:`mongoc_cursor_t` that should be freed with :symbol:`mongoc_cursor_destroy()` when no longer in use.
54+
.. include:: includes/returns-cursor.txt
5555

5656
Example
5757
-------

src/libmongoc/doc/mongoc_collection_find_indexes.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,9 @@ Errors are propagated via the ``error`` parameter.
3737
Returns
3838
-------
3939

40-
A cursor where each result corresponds to the server's representation of an index on this collection. If the collection does not exist on the server, the cursor will be empty.
40+
.. include:: includes/returns-cursor.txt
41+
42+
In the returned cursor each result corresponds to the server's representation of an index on this collection. If the collection does not exist on the server, the cursor will be empty.
43+
44+
The cursor functions :symbol:`mongoc_cursor_set_limit`, :symbol:`mongoc_cursor_set_batch_size`, and :symbol:`mongoc_cursor_set_max_await_time_ms` have no use on the returned cursor.
45+

src/libmongoc/doc/mongoc_collection_find_indexes_with_opts.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ Use :symbol:`mongoc_cursor_error` on the returned cursor to check for errors.
3434
Returns
3535
-------
3636

37-
A cursor where each result corresponds to the server's representation of an index on this collection. If the collection does not exist on the server, the cursor will be empty.
37+
.. include:: includes/returns-cursor.txt
38+
39+
In the returned cursor each result corresponds to the server's representation of an index on this collection. If the collection does not exist on the server, the cursor will be empty.
3840

3941
The cursor functions :symbol:`mongoc_cursor_set_limit`, :symbol:`mongoc_cursor_set_batch_size`, and :symbol:`mongoc_cursor_set_max_await_time_ms` have no use on the returned cursor.
4042

src/libmongoc/doc/mongoc_collection_find_with_opts.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ To target a specific server, include an integer "serverId" field in ``opts`` wit
3939
Returns
4040
-------
4141

42-
A newly allocated :symbol:`mongoc_cursor_t` that must be freed with :symbol:`mongoc_cursor_destroy()`.
42+
.. include:: includes/returns-cursor.txt
4343

4444
Examples
4545
--------

src/libmongoc/doc/mongoc_database_aggregate.rst

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,7 @@ Transaction Transaction Transaction
5151
Returns
5252
-------
5353

54-
This function returns a newly allocated :symbol:`mongoc_cursor_t` that should be freed with :symbol:`mongoc_cursor_destroy()` when no longer in use. The returned :symbol:`mongoc_cursor_t` is never ``NULL``; if the parameters are invalid, the :symbol:`bson:bson_error_t` in the :symbol:`mongoc_cursor_t` is filled out, and the :symbol:`mongoc_cursor_t` is returned before the server is selected. The user must call :symbol:`mongoc_cursor_next()` on the returned :symbol:`mongoc_cursor_t` to execute the aggregation pipeline.
55-
56-
.. warning::
57-
58-
Failure to handle the result of this function is a programming error.
54+
.. include:: includes/returns-cursor.txt
5955

6056
Example
6157
-------

src/libmongoc/doc/mongoc_database_command.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,5 @@ Parameters
4242
Returns
4343
-------
4444

45-
A :symbol:`mongoc_cursor_t`.
46-
47-
The cursor should be freed with :symbol:`mongoc_cursor_destroy()`.
45+
.. include:: includes/returns-cursor.txt
4846

src/libmongoc/doc/mongoc_database_find_collections.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,8 @@ Errors are propagated via the ``error`` parameter.
4343
Returns
4444
-------
4545

46-
A cursor where each result corresponds to the server's representation of a collection in this database.
46+
This function returns a newly allocated :symbol:`mongoc_cursor_t` that should be freed with :symbol:`mongoc_cursor_destroy()` when no longer in use, or `NULL` in case of error. The user must call :symbol:`mongoc_cursor_next()` on the returned :symbol:`mongoc_cursor_t` to execute the initial command.
4747

48+
In the returned cursor each result corresponds to the server's representation of a collection in this database.
49+
50+
The cursor functions :symbol:`mongoc_cursor_set_limit`, :symbol:`mongoc_cursor_set_batch_size`, and :symbol:`mongoc_cursor_set_max_await_time_ms` have no use on the returned cursor.

src/libmongoc/doc/mongoc_database_find_collections_with_opts.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ Use :symbol:`mongoc_cursor_error` on the returned cursor to check for errors.
3838
Returns
3939
-------
4040

41-
A cursor where each result corresponds to the server's representation of a collection in this database.
41+
.. include:: includes/returns-cursor.txt
42+
43+
In the returned cursor each result corresponds to the server's representation of a collection in this database.
4244

4345
The cursor functions :symbol:`mongoc_cursor_set_limit`, :symbol:`mongoc_cursor_set_batch_size`, and :symbol:`mongoc_cursor_set_max_await_time_ms` have no use on the returned cursor.
4446

0 commit comments

Comments
 (0)