Skip to content

Commit 7c7e5bf

Browse files
committed
CDRIVER-1985 Deprecate mongoc_collection_save
1 parent 0a9cd93 commit 7c7e5bf

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

doc/mongoc_collection_save.rst

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@
33
mongoc_collection_save()
44
========================
55

6+
Deprecated
7+
----------
8+
9+
This function is deprecated and should not be used in new code.
10+
11+
Please use :symbol:`mongoc_collection_insert() <mongoc_collection_insert>` or
12+
:symbol:`mongoc_collection_update() <mongoc_collection_update>` instead.
13+
14+
615
Synopsis
716
--------
817

@@ -12,7 +21,8 @@ Synopsis
1221
mongoc_collection_save (mongoc_collection_t *collection,
1322
const bson_t *document,
1423
const mongoc_write_concern_t *write_concern,
15-
bson_error_t *error);
24+
bson_error_t *error)
25+
BSON_GNUC_DEPRECATED_FOR (mongoc_collection_insert or mongoc_collection_update);
1626
1727
Parameters
1828
----------

src/mongoc/mongoc-collection.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ BSON_EXPORT (bool)
188188
mongoc_collection_save (mongoc_collection_t *collection,
189189
const bson_t *document,
190190
const mongoc_write_concern_t *write_concern,
191-
bson_error_t *error);
191+
bson_error_t *error)
192+
BSON_GNUC_DEPRECATED_FOR (mongoc_collection_insert or mongoc_collection_update);
192193
BSON_EXPORT (bool)
193194
mongoc_collection_remove (mongoc_collection_t *collection,
194195
mongoc_remove_flags_t flags,

src/mongoc/mongoc-database.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ mongoc_database_add_user_legacy (mongoc_database_t *database,
414414
bson_append_utf8 (&user, "pwd", 3, pwd, -1);
415415
}
416416

417-
if (!mongoc_collection_save (collection, &user, NULL, error)) {
417+
if (!mongoc_collection_insert (collection, MONGOC_INSERT_NONE, &user, NULL, error)) {
418418
GOTO (failure_with_user);
419419
}
420420

tests/test-mongoc-collection.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,6 +1231,8 @@ test_save (void)
12311231
context = bson_context_new (BSON_CONTEXT_NONE);
12321232
ASSERT (context);
12331233

1234+
BEGIN_IGNORE_DEPRECATIONS;
1235+
12341236
for (i = 0; i < 10; i++) {
12351237
bson_init (&b);
12361238
bson_oid_init (&oid, context);
@@ -1253,6 +1255,9 @@ test_save (void)
12531255

12541256
r = mongoc_collection_save (
12551257
collection, tmp_bson ("{'a.b': 1}"), NULL, &error);
1258+
1259+
END_IGNORE_DEPRECATIONS;
1260+
12561261
ASSERT (!r);
12571262
ASSERT_ERROR_CONTAINS (error,
12581263
MONGOC_ERROR_COMMAND,

0 commit comments

Comments
 (0)