Skip to content

Commit 45f6283

Browse files
CXX-1943 properly deprecate create_collection method and options
1 parent 8fd9fbd commit 45f6283

File tree

6 files changed

+55
-41
lines changed

6 files changed

+55
-41
lines changed

src/mongocxx/database.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ collection database::_create_collection(const client_session* session,
296296
collection database::_create_collection_deprecated(
297297
const client_session* session,
298298
bsoncxx::string::view_or_value name,
299-
const options::create_collection& collection_options,
299+
const options::create_collection_deprecated& collection_options,
300300
const stdx::optional<class write_concern>& write_concern) {
301301
bsoncxx::builder::basic::document options_builder;
302302

@@ -384,15 +384,15 @@ class collection database::create_collection(
384384

385385
class collection database::create_collection_deprecated(
386386
bsoncxx::string::view_or_value name,
387-
const options::create_collection& collection_options,
387+
const options::create_collection_deprecated& collection_options,
388388
const stdx::optional<class write_concern>& write_concern) {
389389
return _create_collection_deprecated(nullptr, name, collection_options, write_concern);
390390
}
391391

392392
class collection database::create_collection_deprecated(
393393
const client_session& session,
394394
bsoncxx::string::view_or_value name,
395-
const options::create_collection& collection_options,
395+
const options::create_collection_deprecated& collection_options,
396396
const stdx::optional<class write_concern>& write_concern) {
397397
return _create_collection_deprecated(&session, name, collection_options, write_concern);
398398
}

src/mongocxx/database.hpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -249,15 +249,16 @@ class MONGOCXX_API database {
249249
/// @exception
250250
/// mongocxx::operation_exception if the operation fails.
251251
///
252-
class collection create_collection(bsoncxx::string::view_or_value name,
253-
const options::create_collection& collection_options,
254-
const stdx::optional<write_concern>& write_concern = {}) {
252+
MONGOCXX_DEPRECATED class collection create_collection(
253+
bsoncxx::string::view_or_value name,
254+
const options::create_collection_deprecated& collection_options,
255+
const stdx::optional<write_concern>& write_concern = {}) {
255256
return create_collection_deprecated(name, collection_options, write_concern);
256257
}
257258

258259
class collection create_collection_deprecated(
259260
bsoncxx::string::view_or_value name,
260-
const options::create_collection& collection_options,
261+
const options::create_collection_deprecated& collection_options,
261262
const stdx::optional<write_concern>& write_concern = {});
262263

263264
///
@@ -283,17 +284,18 @@ class MONGOCXX_API database {
283284
/// @exception
284285
/// mongocxx::operation_exception if the operation fails.
285286
///
286-
class collection create_collection(const client_session& session,
287-
bsoncxx::string::view_or_value name,
288-
const options::create_collection& collection_options,
289-
const stdx::optional<write_concern>& write_concern = {}) {
287+
MONGOCXX_DEPRECATED class collection create_collection(
288+
const client_session& session,
289+
bsoncxx::string::view_or_value name,
290+
const options::create_collection_deprecated& collection_options,
291+
const stdx::optional<write_concern>& write_concern = {}) {
290292
return create_collection_deprecated(session, name, collection_options, write_concern);
291293
}
292294

293295
class collection create_collection_deprecated(
294296
const client_session& session,
295297
bsoncxx::string::view_or_value name,
296-
const options::create_collection& collection_options,
298+
const options::create_collection_deprecated& collection_options,
297299
const stdx::optional<write_concern>& write_concern = {});
298300

299301
///
@@ -613,7 +615,7 @@ class MONGOCXX_API database {
613615
MONGOCXX_PRIVATE class collection _create_collection_deprecated(
614616
const client_session* session,
615617
bsoncxx::string::view_or_value name,
616-
const options::create_collection& collection_options,
618+
const options::create_collection_deprecated& collection_options,
617619
const stdx::optional<class write_concern>& write_concern);
618620

619621
MONGOCXX_PRIVATE cursor _list_collections(const client_session* session,

src/mongocxx/options/create_collection.cpp

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,71 +28,76 @@ namespace mongocxx {
2828
MONGOCXX_INLINE_NAMESPACE_BEGIN
2929
namespace options {
3030

31-
create_collection& create_collection::capped(bool capped) {
31+
create_collection_deprecated& create_collection_deprecated::capped(bool capped) {
3232
_capped = capped;
3333
return *this;
3434
}
3535

36-
create_collection& create_collection::collation(bsoncxx::document::view_or_value collation) {
36+
create_collection_deprecated& create_collection_deprecated::collation(
37+
bsoncxx::document::view_or_value collation) {
3738
_collation = std::move(collation);
3839
return *this;
3940
}
4041

41-
create_collection& create_collection::max(std::int64_t max_documents) {
42+
create_collection_deprecated& create_collection_deprecated::max(std::int64_t max_documents) {
4243
_max_documents = max_documents;
4344
return *this;
4445
}
4546

46-
create_collection& create_collection::no_padding(bool no_padding) {
47+
create_collection_deprecated& create_collection_deprecated::no_padding(bool no_padding) {
4748
_no_padding = no_padding;
4849
return *this;
4950
}
5051

51-
create_collection& create_collection::size(std::int64_t max_size) {
52+
create_collection_deprecated& create_collection_deprecated::size(std::int64_t max_size) {
5253
_max_size = max_size;
5354
return *this;
5455
}
5556

56-
create_collection& create_collection::storage_engine(
57+
create_collection_deprecated& create_collection_deprecated::storage_engine(
5758
bsoncxx::document::view_or_value storage_engine_opts) {
5859
_storage_engine_opts = std::move(storage_engine_opts);
5960
return *this;
6061
}
6162

62-
create_collection& create_collection::validation_criteria(class validation_criteria validation) {
63+
create_collection_deprecated& create_collection_deprecated::validation_criteria(
64+
class validation_criteria validation) {
6365
_validation = std::move(validation);
6466
return *this;
6567
}
6668

67-
const stdx::optional<bool>& create_collection::capped() const {
69+
const stdx::optional<bool>& create_collection_deprecated::capped() const {
6870
return _capped;
6971
}
7072

71-
const stdx::optional<bsoncxx::document::view_or_value>& create_collection::collation() const {
73+
const stdx::optional<bsoncxx::document::view_or_value>& create_collection_deprecated::collation()
74+
const {
7275
return _collation;
7376
}
7477

75-
const stdx::optional<std::int64_t>& create_collection::max() const {
78+
const stdx::optional<std::int64_t>& create_collection_deprecated::max() const {
7679
return _max_documents;
7780
}
7881

79-
const stdx::optional<bool>& create_collection::no_padding() const {
82+
const stdx::optional<bool>& create_collection_deprecated::no_padding() const {
8083
return _no_padding;
8184
}
8285

83-
const stdx::optional<std::int64_t>& create_collection::size() const {
86+
const stdx::optional<std::int64_t>& create_collection_deprecated::size() const {
8487
return _max_size;
8588
}
8689

87-
const stdx::optional<bsoncxx::document::view_or_value>& create_collection::storage_engine() const {
90+
const stdx::optional<bsoncxx::document::view_or_value>&
91+
create_collection_deprecated::storage_engine() const {
8892
return _storage_engine_opts;
8993
}
9094

91-
const stdx::optional<class validation_criteria>& create_collection::validation_criteria() const {
95+
const stdx::optional<class validation_criteria>& create_collection_deprecated::validation_criteria()
96+
const {
9297
return _validation;
9398
}
9499

95-
bsoncxx::document::value create_collection::to_document_deprecated() const {
100+
bsoncxx::document::value create_collection_deprecated::to_document_deprecated() const {
96101
auto doc = bsoncxx::builder::basic::document{};
97102

98103
if (_capped) {
@@ -126,7 +131,7 @@ bsoncxx::document::value create_collection::to_document_deprecated() const {
126131
return doc.extract();
127132
}
128133

129-
bsoncxx::document::value create_collection::to_document() const {
134+
bsoncxx::document::value create_collection_deprecated::to_document() const {
130135
return to_document_deprecated();
131136
}
132137

src/mongocxx/options/create_collection.hpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ namespace options {
2828
///
2929
/// Class representing the optional arguments to a MongoDB createCollection command
3030
///
31-
class MONGOCXX_API create_collection {
31+
/// This class is deprecated, as are the database class methods that use this class.
32+
/// Please use the new database::create_collection methods that take options as a
33+
/// BSON document.
34+
///
35+
class MONGOCXX_API create_collection_deprecated {
3236
public:
3337
///
3438
/// To create a capped collection, specify true.
@@ -44,7 +48,7 @@ class MONGOCXX_API create_collection {
4448
///
4549
/// @see https://docs.mongodb.com/master/reference/glossary/#term-capped-collection
4650
///
47-
create_collection& capped(bool capped);
51+
create_collection_deprecated& capped(bool capped);
4852

4953
///
5054
/// Gets the current capped setting.
@@ -69,7 +73,7 @@ class MONGOCXX_API create_collection {
6973
/// @see
7074
/// https://docs.mongodb.com/master/reference/collation/
7175
///
72-
create_collection& collation(bsoncxx::document::view_or_value collation);
76+
create_collection_deprecated& collation(bsoncxx::document::view_or_value collation);
7377

7478
///
7579
/// Gets the default collation for this collection.
@@ -96,7 +100,7 @@ class MONGOCXX_API create_collection {
96100
/// A reference to the object on which this member function is being called. This facilitates
97101
/// method chaining.
98102
///
99-
create_collection& max(std::int64_t max_documents);
103+
create_collection_deprecated& max(std::int64_t max_documents);
100104

101105
///
102106
/// Gets the current setting for the maximum number of documents allowed in the capped
@@ -119,7 +123,7 @@ class MONGOCXX_API create_collection {
119123
/// A reference to the object on which this member function is being called. This facilitates
120124
/// method chaining.
121125
///
122-
create_collection& no_padding(bool no_padding);
126+
create_collection_deprecated& no_padding(bool no_padding);
123127

124128
///
125129
/// Gets the current value of the "no padding" option for the collection.
@@ -146,7 +150,7 @@ class MONGOCXX_API create_collection {
146150
/// A reference to the object on which this member function is being called. This facilitates
147151
/// method chaining.
148152
///
149-
create_collection& size(std::int64_t max_size);
153+
create_collection_deprecated& size(std::int64_t max_size);
150154

151155
///
152156
/// Gets the current size setting, for a capped collection.
@@ -168,7 +172,8 @@ class MONGOCXX_API create_collection {
168172
/// A reference to the object on which this member function is being called. This facilitates
169173
/// method chaining.
170174
///
171-
create_collection& storage_engine(bsoncxx::document::view_or_value storage_engine_opts);
175+
create_collection_deprecated& storage_engine(
176+
bsoncxx::document::view_or_value storage_engine_opts);
172177

173178
///
174179
/// Gets the current storage engine configuration for this collection.
@@ -190,7 +195,7 @@ class MONGOCXX_API create_collection {
190195
///
191196
/// @see https://docs.mongodb.com/master/core/document-validation/
192197
///
193-
create_collection& validation_criteria(class validation_criteria validation);
198+
create_collection_deprecated& validation_criteria(class validation_criteria validation);
194199

195200
///
196201
/// Gets the current validation criteria for this collection.
@@ -231,7 +236,9 @@ class MONGOCXX_API create_collection {
231236
stdx::optional<class validation_criteria> _validation;
232237
};
233238

234-
MONGOCXX_INLINE create_collection::operator bsoncxx::document::value() const {
239+
MONGOCXX_DEPRECATED typedef create_collection_deprecated create_collection;
240+
241+
MONGOCXX_INLINE create_collection_deprecated::operator bsoncxx::document::value() const {
235242
return to_document_deprecated();
236243
}
237244

src/mongocxx/test/database.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ TEST_CASE("Database integration tests", "[database]") {
386386
SECTION("with deprecated options") {
387387
database[collection_name].drop();
388388

389-
options::create_collection opts;
389+
options::create_collection_deprecated opts;
390390
opts.capped(true);
391391
opts.size(256);
392392
opts.max(100);

src/mongocxx/test/options/create_collection.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ using builder::basic::make_document;
3535
TEST_CASE("create_collection accessors/mutators", "[create_collection]") {
3636
instance::current();
3737

38-
options::create_collection cc;
38+
options::create_collection_deprecated cc;
3939

4040
auto collation = make_document(kvp("locale", "en_US"));
4141
auto storage_engine = make_document(
@@ -68,7 +68,7 @@ TEST_CASE("create_collection accessors/mutators", "[create_collection]") {
6868
TEST_CASE("create_collection can be exported to a document", "[create_collection]") {
6969
instance::current();
7070

71-
options::create_collection cc;
71+
options::create_collection_deprecated cc;
7272

7373
auto collation_en_US = make_document(kvp("locale", "en_US"));
7474
auto rule = make_document(kvp("brain", make_document(kvp("$exists", true))));

0 commit comments

Comments
 (0)