Skip to content

Commit 8fed501

Browse files
committed
CDRIVER-2206 mongoc_read/write_concern_is_default
New function mongoc_write_concern_is_default determines if any write concern options have been set, and mongoc_read_concern_is_default checks if read concern options are set.
1 parent 2a4ace5 commit 8fed501

15 files changed

+63
-18
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ mongo-c-driver 1.7.0
3838
* Case is now preserved in Unix domain paths.
3939
* New function mongoc_cursor_error_document provides access to server's error
4040
reply if a query or command fails.
41+
* New function mongoc_write_concern_is_default determines whether any write
42+
concern options have been set, and mongoc_read_concern_is_default checks if
43+
read concern options are set.
4144
* mongoc_gridfs_find_one_with_opts optimized to use limit 1.
4245

4346
mongo-c-driver 1.6.0
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
:man_page: mongoc_read_concern_is_default
2+
3+
mongoc_read_concern_is_default()
4+
================================
5+
6+
Synopsis
7+
--------
8+
9+
.. code-block:: c
10+
11+
bool
12+
mongoc_read_concern_is_default (mongoc_read_concern_t *read_concern);
13+
14+
Parameters
15+
----------
16+
17+
* ``read_concern``: A pointer to a :symbol:`mongoc_read_concern_t`.
18+
19+
Description
20+
-----------
21+
22+
Returns true if ``read_concern`` has not been modified from the default. For example, if no "readConcern" option is set in the MongoDB URI and you have not called :symbol:`mongoc_client_set_read_concern()`, then :symbol:`mongoc_read_concern_is_default()` is true for the read concern returned by :symbol:`mongoc_client_get_read_concern()`.

doc/mongoc_read_concern_t.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ See `Read Concern Levels <https://docs.mongodb.com/master/reference/read-concern
4848
mongoc_read_concern_copy
4949
mongoc_read_concern_destroy
5050
mongoc_read_concern_get_level
51+
mongoc_read_concern_is_default
5152
mongoc_read_concern_new
5253
mongoc_read_concern_set_level
5354

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
:man_page: mongoc_write_concern_is_default
2+
3+
mongoc_write_concern_is_default()
4+
=================================
5+
6+
Synopsis
7+
--------
8+
9+
.. code-block:: c
10+
11+
bool
12+
mongoc_write_concern_is_default (mongoc_write_concern_t *write_concern);
13+
14+
Parameters
15+
----------
16+
17+
* ``write_concern``: A pointer to a :symbol:`mongoc_write_concern_t`.
18+
19+
Description
20+
-----------
21+
22+
Returns true if ``write_concern`` has not been modified from the default. For example, if no "w" option is set in the MongoDB URI and you have not called :symbol:`mongoc_client_set_write_concern()`, then
23+
:symbol:`mongoc_write_concern_is_default()` is true for the write concern returned by :symbol:`mongoc_client_get_write_concern()`.

doc/mongoc_write_concern_t.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ The write concern ``MONGOC_WRITE_CONCERN_W_ERRORS_IGNORED`` (value -1) is a depr
6363
mongoc_write_concern_get_wtag
6464
mongoc_write_concern_get_wtimeout
6565
mongoc_write_concern_is_acknowledged
66+
mongoc_write_concern_is_default
6667
mongoc_write_concern_is_valid
6768
mongoc_write_concern_journal_is_set
6869
mongoc_write_concern_new

src/mongoc/mongoc-client.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,7 +1452,7 @@ _mongoc_client_command_with_opts (mongoc_client_t *client,
14521452
if ((mode & MONGOC_CMD_WRITE) &&
14531453
server_stream->sd->max_wire_version >=
14541454
WIRE_VERSION_CMD_WRITE_CONCERN &&
1455-
!_mongoc_write_concern_is_default (default_wc) &&
1455+
!mongoc_write_concern_is_default (default_wc) &&
14561456
(!command_with_opts ||
14571457
!bson_has_field (command_with_opts, "writeConcern"))) {
14581458
_ensure_copied (&command_with_opts, command);
@@ -1465,7 +1465,7 @@ _mongoc_client_command_with_opts (mongoc_client_t *client,
14651465
/* use read prefs and read concern for read commands, unless in opts */
14661466
if ((mode & MONGOC_CMD_READ) &&
14671467
server_stream->sd->max_wire_version >= WIRE_VERSION_READ_CONCERN &&
1468-
!_mongoc_read_concern_is_default (default_rc) &&
1468+
!mongoc_read_concern_is_default (default_rc) &&
14691469
(!command_with_opts ||
14701470
!bson_has_field (command_with_opts, "readConcern"))) {
14711471
_ensure_copied (&command_with_opts, command);

src/mongoc/mongoc-cursor.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1304,7 +1304,7 @@ _mongoc_cursor_run_command (mongoc_cursor_t *cursor,
13041304
cursor->read_prefs, server_stream, command, flags, &read_prefs_result);
13051305

13061306
if (cursor->write_concern &&
1307-
!_mongoc_write_concern_is_default (cursor->write_concern) &&
1307+
!mongoc_write_concern_is_default (cursor->write_concern) &&
13081308
server_stream->sd->max_wire_version >= WIRE_VERSION_CMD_WRITE_CONCERN) {
13091309
mongoc_write_concern_append (cursor->write_concern,
13101310
read_prefs_result.query_with_read_prefs);

src/mongoc/mongoc-read-concern-private.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ struct _mongoc_read_concern_t {
3535
};
3636

3737

38-
bool
39-
_mongoc_read_concern_is_default (const mongoc_read_concern_t *read_concern);
4038
const bson_t *
4139
_mongoc_read_concern_get_bson (mongoc_read_concern_t *read_concern);
4240

src/mongoc/mongoc-read-concern.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,15 +152,13 @@ mongoc_read_concern_append (mongoc_read_concern_t *read_concern,
152152

153153

154154
/**
155-
* _mongoc_read_concern_is_default:
155+
* mongoc_read_concern_is_default:
156156
* @read_concern: A const mongoc_read_concern_t.
157157
*
158-
* This is an internal function.
159-
*
160158
* Returns true when read_concern has not been modified.
161159
*/
162160
bool
163-
_mongoc_read_concern_is_default (const mongoc_read_concern_t *read_concern)
161+
mongoc_read_concern_is_default (const mongoc_read_concern_t *read_concern)
164162
{
165163
return !read_concern || !read_concern->level;
166164
}

src/mongoc/mongoc-read-concern.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ mongoc_read_concern_set_level (mongoc_read_concern_t *read_concern,
4848
const char *level);
4949
MONGOC_EXPORT (bool)
5050
mongoc_read_concern_append (mongoc_read_concern_t *read_concern, bson_t *doc);
51-
51+
MONGOC_EXPORT (bool)
52+
mongoc_read_concern_is_default (const mongoc_read_concern_t *read_concern);
5253

5354
BSON_END_DECLS
5455

0 commit comments

Comments
 (0)