Skip to content

Commit 1a9ca18

Browse files
author
Tess Avitabile
committed
CXX-805 Use options::find::comment()
1 parent 82a33b2 commit 1a9ca18

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/mongocxx/collection.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,10 @@ cursor collection::find(view_or_value filter, const options::find& options) {
212212
filter_builder << builder::stream::concatenate(options.hint()->to_document());
213213
}
214214

215+
if (options.comment()) {
216+
filter_builder << "$comment" << *options.comment();
217+
}
218+
215219
filter_bson.init_from_static(filter_builder.view());
216220

217221
const mongoc_read_prefs_t* rp_ptr = NULL;

src/mongocxx/test/collection_mocked.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,8 @@ TEST_CASE("Collection", "[collection]") {
342342
auto doc = find_doc.view();
343343
mongocxx::stdx::optional<bsoncxx::document::view> expected_sort{};
344344
mongocxx::stdx::optional<bsoncxx::document::view> expected_hint{};
345+
mongocxx::stdx::optional<bsoncxx::stdx::string_view> expected_comment{};
346+
345347

346348
collection_find->interpose([&](mongoc_collection_t*, mongoc_query_flags_t flags,
347349
uint32_t skip, uint32_t limit, uint32_t batch_size,
@@ -365,6 +367,9 @@ TEST_CASE("Collection", "[collection]") {
365367
REQUIRE(query_view["$hint"].get_utf8() ==
366368
expected_hint->operator[]("$hint").get_utf8());
367369
}
370+
if (expected_comment) {
371+
REQUIRE(query_view["$comment"].get_utf8().value == *expected_comment);
372+
}
368373
REQUIRE(fields == NULL);
369374
REQUIRE(read_prefs == NULL);
370375

@@ -396,6 +401,14 @@ TEST_CASE("Collection", "[collection]") {
396401
REQUIRE_NOTHROW(mongo_coll.find(doc, opts));
397402
}
398403

404+
SECTION("Succeeds with comment") {
405+
expected_comment = "my comment";
406+
options::find opts;
407+
opts.comment(*expected_comment);
408+
409+
REQUIRE_NOTHROW(mongo_coll.find(doc, opts));
410+
}
411+
399412
REQUIRE(collection_find_called);
400413
}
401414

0 commit comments

Comments
 (0)