Skip to content

Commit c6f0fbc

Browse files
CDRIVER-4618: updated transaction examples (#1630)
1 parent 2bac313 commit c6f0fbc

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

src/libmongoc/tests/test-mongoc-sample-commands.c

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3639,7 +3639,8 @@ update_employee_info (mongoc_client_session_t *cs, bson_t *reply, bson_error_t *
36393639
rc = mongoc_read_concern_new ();
36403640
mongoc_read_concern_set_level (rc, MONGOC_READ_CONCERN_LEVEL_SNAPSHOT);
36413641
wc = mongoc_write_concern_new ();
3642-
mongoc_write_concern_set_w (wc, MONGOC_WRITE_CONCERN_W_MAJORITY);
3642+
mongoc_write_concern_set_w (
3643+
wc, MONGOC_WRITE_CONCERN_W_MAJORITY); /* Atlas connection strings include majority by default*/
36433644
txn_opts = mongoc_transaction_opts_new ();
36443645
mongoc_transaction_opts_set_read_concern (txn_opts, rc);
36453646
mongoc_transaction_opts_set_write_concern (txn_opts, wc);
@@ -3781,8 +3782,6 @@ with_transaction_example (bson_error_t *error)
37813782
{
37823783
mongoc_client_t *client = NULL;
37833784
mongoc_write_concern_t *wc = NULL;
3784-
mongoc_read_concern_t *rc = NULL;
3785-
mongoc_read_prefs_t *rp = NULL;
37863785
mongoc_collection_t *coll = NULL;
37873786
bool success = false;
37883787
bool ret = false;
@@ -3804,9 +3803,11 @@ with_transaction_example (bson_error_t *error)
38043803

38053804
client = get_client ();
38063805

3807-
/* Prereq: Create collections. */
3806+
/* Prereq: Create collections. Note Atlas connection strings include a majority write
3807+
* concern by default.
3808+
*/
38083809
wc = mongoc_write_concern_new ();
3809-
mongoc_write_concern_set_wmajority (wc, 1000);
3810+
mongoc_write_concern_set_wmajority (wc, 0);
38103811
insert_opts = bson_new ();
38113812
mongoc_write_concern_append (wc, insert_opts);
38123813
coll = mongoc_client_get_collection (client, "mydb1", "foo");
@@ -3832,11 +3833,6 @@ with_transaction_example (bson_error_t *error)
38323833

38333834
/* Step 2: Optional. Define options to use for the transaction. */
38343835
txn_opts = mongoc_transaction_opts_new ();
3835-
rp = mongoc_read_prefs_new (MONGOC_READ_PRIMARY);
3836-
rc = mongoc_read_concern_new ();
3837-
mongoc_read_concern_set_level (rc, MONGOC_READ_CONCERN_LEVEL_LOCAL);
3838-
mongoc_transaction_opts_set_read_prefs (txn_opts, rp);
3839-
mongoc_transaction_opts_set_read_concern (txn_opts, rc);
38403836
mongoc_transaction_opts_set_write_concern (txn_opts, wc);
38413837

38423838
/* Step 3: Use mongoc_client_session_with_transaction to start a transaction,
@@ -3851,8 +3847,6 @@ with_transaction_example (bson_error_t *error)
38513847
bson_destroy (doc);
38523848
mongoc_collection_destroy (coll);
38533849
bson_destroy (insert_opts);
3854-
mongoc_read_concern_destroy (rc);
3855-
mongoc_read_prefs_destroy (rp);
38563850
mongoc_write_concern_destroy (wc);
38573851
mongoc_transaction_opts_destroy (txn_opts);
38583852
mongoc_client_session_destroy (session);

0 commit comments

Comments
 (0)