Skip to content

Commit f2ed9aa

Browse files
authored
CDRIVER-2712 remove deprecated mongoc_collection_save (#1911)
1 parent fe10e17 commit f2ed9aa

File tree

6 files changed

+1
-167
lines changed

6 files changed

+1
-167
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Unreleased (2.0.0)
1515
* `mongoc_server_description_ismaster` is removed. Use the equivalent `mongoc_server_description_hello` instead.
1616
* `MONGOC_QUERY_SLAVE_OK` is removed. Use the equivalent `MONGOC_QUERY_SECONDARY_OK` instead.
1717
* `MONGOC_URI_SLAVEOK` is removed. It was unused.
18+
* `mongoc_collection_save` is removed. Use `mongoc_collection_insert_one` or `mongoc_collection_replace_one` instead.
1819

1920
### Forwarding headers (`#include <bson.h>` and `#include <mongoc.h>`)
2021

src/libmongoc/doc/mongoc_collection_save.rst

Lines changed: 0 additions & 46 deletions
This file was deleted.

src/libmongoc/doc/mongoc_collection_t.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ Read preferences and write concerns are inherited from the parent client. They c
7171
mongoc_collection_rename
7272
mongoc_collection_rename_with_opts
7373
mongoc_collection_replace_one
74-
mongoc_collection_save
7574
mongoc_collection_set_read_concern
7675
mongoc_collection_set_read_prefs
7776
mongoc_collection_set_write_concern

src/libmongoc/src/mongoc/mongoc-collection.c

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -2297,66 +2297,6 @@ mongoc_collection_replace_one (mongoc_collection_t *collection,
22972297
}
22982298

22992299

2300-
/*
2301-
*--------------------------------------------------------------------------
2302-
*
2303-
* mongoc_collection_save --
2304-
*
2305-
* Save @document to @collection.
2306-
*
2307-
* If the document has an _id field, it will be updated. Otherwise,
2308-
* the document will be inserted into the collection.
2309-
*
2310-
* Returns:
2311-
* true if successful; otherwise false and @error is set.
2312-
*
2313-
* Side effects:
2314-
* @error is set upon failure if non-NULL.
2315-
*
2316-
*--------------------------------------------------------------------------
2317-
*/
2318-
2319-
bool
2320-
mongoc_collection_save (mongoc_collection_t *collection,
2321-
const bson_t *document,
2322-
const mongoc_write_concern_t *write_concern,
2323-
bson_error_t *error)
2324-
{
2325-
bson_iter_t iter;
2326-
bool ret;
2327-
bson_t selector;
2328-
2329-
BSON_ASSERT_PARAM (collection);
2330-
BSON_ASSERT_PARAM (document);
2331-
2332-
BEGIN_IGNORE_DEPRECATIONS
2333-
if (!bson_iter_init_find (&iter, document, "_id")) {
2334-
return mongoc_collection_insert (collection, MONGOC_INSERT_NONE, document, write_concern, error);
2335-
}
2336-
2337-
bson_init (&selector);
2338-
if (!bson_append_iter (&selector, NULL, 0, &iter)) {
2339-
_mongoc_set_error (
2340-
error, MONGOC_ERROR_COMMAND, MONGOC_ERROR_COMMAND_INVALID_ARG, "Failed to append bson to create update.");
2341-
bson_destroy (&selector);
2342-
return false;
2343-
}
2344-
2345-
/* this document will be inserted, validate same as for inserts */
2346-
if (!_mongoc_validate_new_document (document, _mongoc_default_insert_vflags, error)) {
2347-
return false;
2348-
}
2349-
2350-
ret = mongoc_collection_update (
2351-
collection, MONGOC_UPDATE_UPSERT | MONGOC_UPDATE_NO_VALIDATE, &selector, document, write_concern, error);
2352-
END_IGNORE_DEPRECATIONS
2353-
2354-
bson_destroy (&selector);
2355-
2356-
return ret;
2357-
}
2358-
2359-
23602300
bool
23612301
mongoc_collection_remove (mongoc_collection_t *collection,
23622302
mongoc_remove_flags_t flags,

src/libmongoc/src/mongoc/mongoc-collection.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -258,12 +258,6 @@ MONGOC_EXPORT (bool) mongoc_collection_delete (mongoc_collection_t *collection,
258258
const mongoc_write_concern_t *write_concern,
259259
bson_error_t *error);
260260

261-
BSON_DEPRECATED_FOR (mongoc_collection_insert_one or mongoc_collection_replace_one)
262-
MONGOC_EXPORT (bool) mongoc_collection_save (mongoc_collection_t *collection,
263-
const bson_t *document,
264-
const mongoc_write_concern_t *write_concern,
265-
bson_error_t *error);
266-
267261
MONGOC_EXPORT (bool)
268262
mongoc_collection_remove (mongoc_collection_t *collection,
269263
mongoc_remove_flags_t flags,

src/libmongoc/tests/test-mongoc-collection.c

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -854,59 +854,6 @@ test_insert_command_keys (void)
854854
}
855855

856856

857-
static void
858-
test_save (void)
859-
{
860-
mongoc_collection_t *collection;
861-
mongoc_database_t *database;
862-
mongoc_client_t *client;
863-
bson_context_t *context;
864-
bson_error_t error;
865-
bson_oid_t oid;
866-
unsigned i;
867-
bson_t b;
868-
bool r;
869-
870-
client = test_framework_new_default_client ();
871-
ASSERT (client);
872-
873-
database = get_test_database (client);
874-
ASSERT (database);
875-
876-
collection = get_test_collection (client, "test_save");
877-
ASSERT (collection);
878-
879-
/* don't care if ns not found. */
880-
(void) mongoc_collection_drop (collection, &error);
881-
882-
context = bson_context_new (BSON_CONTEXT_NONE);
883-
ASSERT (context);
884-
885-
BEGIN_IGNORE_DEPRECATIONS
886-
887-
for (i = 0; i < 10; i++) {
888-
bson_init (&b);
889-
bson_oid_init (&oid, context);
890-
bson_append_oid (&b, "_id", 3, &oid);
891-
bson_append_utf8 (&b, "hello", 5, "/world", 5);
892-
ASSERT_OR_PRINT (mongoc_collection_save (collection, &b, NULL, &error), error);
893-
bson_destroy (&b);
894-
}
895-
896-
r = mongoc_collection_save (collection, tmp_bson ("{'': 1}"), NULL, &error);
897-
898-
END_IGNORE_DEPRECATIONS
899-
900-
ASSERT (!r);
901-
ASSERT_ERROR_CONTAINS (error, MONGOC_ERROR_COMMAND, MONGOC_ERROR_COMMAND_INVALID_ARG, "invalid document");
902-
903-
mongoc_collection_destroy (collection);
904-
mongoc_database_destroy (database);
905-
bson_context_destroy (context);
906-
mongoc_client_destroy (client);
907-
}
908-
909-
910857
static void
911858
test_regex (void)
912859
{
@@ -5810,7 +5757,6 @@ test_collection_install (TestSuite *suite)
58105757
TestSuite_AddFull (
58115758
suite, "/Collection/insert/oversize", test_insert_oversize, NULL, NULL, test_framework_skip_if_slow_or_live);
58125759
TestSuite_AddMockServerTest (suite, "/Collection/insert/keys", test_insert_command_keys);
5813-
TestSuite_AddLive (suite, "/Collection/save", test_save);
58145760
TestSuite_AddLive (suite, "/Collection/insert/w0", test_insert_w0);
58155761
TestSuite_AddLive (suite, "/Collection/update/w0", test_update_w0);
58165762
TestSuite_AddLive (suite, "/Collection/remove/w0", test_remove_w0);

0 commit comments

Comments
 (0)