Skip to content

Commit e0401bb

Browse files
author
Christian Hergert
committed
collection: use write commands for delete/remove.
1 parent 90854c7 commit e0401bb

File tree

1 file changed

+25
-27
lines changed

1 file changed

+25
-27
lines changed

src/mongoc/mongoc-collection.c

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,6 +1000,10 @@ mongoc_collection_insert (mongoc_collection_t *collection,
10001000

10011001
bson_clear (&collection->gle);
10021002

1003+
if (!write_concern) {
1004+
write_concern = collection->write_concern;
1005+
}
1006+
10031007
if (!(flags & MONGOC_INSERT_NO_VALIDATE)) {
10041008
if (!bson_validate (document,
10051009
(BSON_VALIDATE_UTF8 |
@@ -1217,44 +1221,38 @@ mongoc_collection_remove (mongoc_collection_t *collection,
12171221
const mongoc_write_concern_t *write_concern,
12181222
bson_error_t *error)
12191223
{
1220-
uint32_t hint;
1221-
mongoc_rpc_t rpc;
1224+
mongoc_write_command_t command;
1225+
mongoc_write_result_t result;
1226+
bool multi;
1227+
bool ret;
12221228

1223-
bson_return_val_if_fail(collection, false);
1224-
bson_return_val_if_fail(selector, false);
1229+
ENTRY;
1230+
1231+
bson_return_val_if_fail (collection, false);
1232+
bson_return_val_if_fail (selector, false);
12251233

12261234
bson_clear (&collection->gle);
12271235

12281236
if (!write_concern) {
12291237
write_concern = collection->write_concern;
12301238
}
12311239

1232-
if (!_mongoc_client_warm_up (collection->client, error)) {
1233-
return false;
1234-
}
1240+
multi = !(flags & MONGOC_REMOVE_SINGLE_REMOVE);
12351241

1236-
rpc.delete.msg_len = 0;
1237-
rpc.delete.request_id = 0;
1238-
rpc.delete.response_to = 0;
1239-
rpc.delete.opcode = MONGOC_OPCODE_DELETE;
1240-
rpc.delete.zero = 0;
1241-
rpc.delete.collection = collection->ns;
1242-
rpc.delete.flags = flags;
1243-
rpc.delete.selector = bson_get_data(selector);
1244-
1245-
if (!(hint = _mongoc_client_sendv(collection->client, &rpc, 1, 0,
1246-
write_concern, NULL, error))) {
1247-
return false;
1248-
}
1242+
_mongoc_write_result_init (&result);
1243+
_mongoc_write_command_init_delete (&command, selector, multi, true);
12491244

1250-
if (_mongoc_write_concern_has_gle(write_concern)) {
1251-
if (!_mongoc_client_recv_gle (collection->client, hint,
1252-
&collection->gle, error)) {
1253-
return false;
1254-
}
1255-
}
1245+
_mongoc_write_command_execute (&command, collection->client, 0,
1246+
collection->db, collection->collection,
1247+
write_concern, &result);
12561248

1257-
return true;
1249+
collection->gle = bson_new ();
1250+
ret = _mongoc_write_result_complete (&result, collection->gle, error);
1251+
1252+
_mongoc_write_result_destroy (&result);
1253+
_mongoc_write_command_destroy (&command);
1254+
1255+
RETURN (ret);
12581256
}
12591257

12601258

0 commit comments

Comments
 (0)