Skip to content

Commit b8e69d1

Browse files
committed
CXX-1006 Bulk-format examples/ with standard repository style
1 parent 4e49da5 commit b8e69d1

File tree

4 files changed

+38
-41
lines changed

4 files changed

+38
-41
lines changed

examples/bsoncxx/builder_stream.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ int main(int, char**) {
7777
bsoncxx::document::value nestedValue = document{} << "nested" << true << finalize;
7878
document topLevelDoc{};
7979
topLevelDoc << "subDoc1" << types::b_document{nestedValue.view()} << "subDoc2" << open_document
80-
<< concatenate(nestedValue.view()) << close_document << "subDoc3"
81-
<< nestedValue << finalize;
80+
<< concatenate(nestedValue.view()) << close_document << "subDoc3" << nestedValue
81+
<< finalize;
8282

8383
// `topLevelDoc` now looks like:
8484
// {

examples/mongocxx/exception.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ int main(int, char**) {
6363
return EXIT_FAILURE;
6464
}
6565

66-
std::cout << e.what() << std::endl << std::endl;
66+
std::cout << e.what() << std::endl
67+
<< std::endl;
6768
}
6869
// @end: cpp-logic-error
6970

examples/mongocxx/instance_management.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ namespace {
3636
// and share the instance and pool objects between multiple functions.
3737

3838
class mongo_access {
39-
public:
40-
39+
public:
4140
static mongo_access& instance() {
4241
static mongo_access instance;
4342
return instance;
@@ -59,7 +58,7 @@ class mongo_access {
5958
return _pool->try_acquire();
6059
}
6160

62-
private:
61+
private:
6362
mongo_access() = default;
6463

6564
std::unique_ptr<mongocxx::instance> _instance = nullptr;
@@ -73,22 +72,20 @@ class mongo_access {
7372

7473
void configure(mongocxx::uri uri) {
7574
class noop_logger : public mongocxx::logger {
76-
public:
75+
public:
7776
virtual void operator()(mongocxx::log_level, mongocxx::stdx::string_view,
78-
mongocxx::stdx::string_view) noexcept {}
77+
mongocxx::stdx::string_view) noexcept {
78+
}
7979
};
8080

8181
mongo_access::instance().configure(
8282
mongocxx::stdx::make_unique<mongocxx::instance>(mongocxx::stdx::make_unique<noop_logger>()),
83-
mongocxx::stdx::make_unique<mongocxx::pool>(std::move(uri))
84-
);
85-
83+
mongocxx::stdx::make_unique<mongocxx::pool>(std::move(uri)));
8684
}
8785

8886
bool do_work() {
8987
auto connection = mongo_access::instance().get_connection();
90-
if (!connection)
91-
return false;
88+
if (!connection) return false;
9289
return true;
9390
}
9491

examples/mongocxx/query_projection.cpp

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,31 @@ using bsoncxx::builder::stream::close_document;
1414
using bsoncxx::builder::stream::finalize;
1515

1616
int main(int, char **) {
17-
mongocxx::instance inst{};
18-
mongocxx::client conn{mongocxx::uri{}};
19-
20-
auto coll = conn["test"]["query_projection"];
21-
coll.drop();
22-
23-
// Insert a test document
24-
auto joe = document{} << "user info" << open_document << "user name"
25-
<< "Joe" << close_document << finalize;
26-
auto result = coll.insert_one(joe.view());
27-
std::cout << "Inserted " << result->inserted_id().get_oid().value.to_string()
28-
<< std::endl;
29-
30-
// Create the query filter
31-
auto filter = document{} << "user info.user name"
32-
<< "Joe" << finalize;
33-
34-
// Create the find options with the projection
35-
mongocxx::options::find opts{};
36-
opts.projection(document{} << "_id" << 1 << finalize);
37-
38-
// Execute find with options
39-
auto cursor = coll.find(filter.view(), opts);
40-
for (auto &&doc : cursor) {
41-
std::cout << bsoncxx::to_json(doc) << std::endl;
42-
}
43-
44-
return EXIT_SUCCESS;
17+
mongocxx::instance inst{};
18+
mongocxx::client conn{mongocxx::uri{}};
19+
20+
auto coll = conn["test"]["query_projection"];
21+
coll.drop();
22+
23+
// Insert a test document
24+
auto joe = document{} << "user info" << open_document << "user name"
25+
<< "Joe" << close_document << finalize;
26+
auto result = coll.insert_one(joe.view());
27+
std::cout << "Inserted " << result->inserted_id().get_oid().value.to_string() << std::endl;
28+
29+
// Create the query filter
30+
auto filter = document{} << "user info.user name"
31+
<< "Joe" << finalize;
32+
33+
// Create the find options with the projection
34+
mongocxx::options::find opts{};
35+
opts.projection(document{} << "_id" << 1 << finalize);
36+
37+
// Execute find with options
38+
auto cursor = coll.find(filter.view(), opts);
39+
for (auto &&doc : cursor) {
40+
std::cout << bsoncxx::to_json(doc) << std::endl;
41+
}
42+
43+
return EXIT_SUCCESS;
4544
}

0 commit comments

Comments
 (0)