void mongoc_bulk_operation_remove_one (mongoc_bulk_operation_t *bulk, /* IN */ const bson_t *selector) /* IN */ { mongoc_write_command_t command = { 0 }; mongoc_write_command_t *last; ENTRY; BSON_ASSERT (bulk); BSON_ASSERT (selector); if (bulk->commands.len) { last = &_mongoc_array_index (&bulk->commands, mongoc_write_command_t, bulk->commands.len - 1); if ((last->type == MONGOC_WRITE_COMMAND_DELETE) && !last->u.delete_.multi) { _mongoc_write_command_delete_append (last, selector); EXIT; } } _mongoc_write_command_init_delete (&command, selector, false, bulk->flags, bulk->operation_id); _mongoc_array_append_val (&bulk->commands, command); EXIT; }
void _mongoc_write_command_init_delete (mongoc_write_command_t *command, /* IN */ const bson_t *selector, /* IN */ const bson_t *cmd_opts, /* IN */ const bson_t *opts, /* IN */ mongoc_bulk_write_flags_t flags, /* IN */ int64_t operation_id) /* IN */ { ENTRY; BSON_ASSERT (command); BSON_ASSERT (selector); _mongoc_write_command_init_bulk ( command, MONGOC_WRITE_COMMAND_DELETE, flags, operation_id, cmd_opts); _mongoc_write_command_delete_append (command, selector, opts); EXIT; }
void _mongoc_write_command_init_delete_idl (mongoc_write_command_t *command, const bson_t *selector, const bson_t *cmd_opts, const bson_t *opts, int64_t operation_id) { mongoc_bulk_write_flags_t flags = MONGOC_BULK_WRITE_FLAGS_INIT; ENTRY; BSON_ASSERT (command); BSON_ASSERT (selector); _mongoc_write_command_init_bulk ( command, MONGOC_WRITE_COMMAND_DELETE, flags, operation_id, cmd_opts); _mongoc_write_command_delete_append (command, selector, opts); EXIT; }
void _mongoc_write_command_init_delete (mongoc_write_command_t *command, /* IN */ const bson_t *selector, /* IN */ bool multi, /* IN */ mongoc_bulk_write_flags_t flags) /* IN */ { ENTRY; BSON_ASSERT (command); BSON_ASSERT (selector); command->type = MONGOC_WRITE_COMMAND_DELETE; command->documents = bson_new (); command->n_documents = 0; command->u.delete_.multi = (uint8_t)multi; command->flags = flags; command->hint = 0; _mongoc_write_command_delete_append (command, selector); EXIT; }
bool _mongoc_bulk_operation_remove_with_opts ( mongoc_bulk_operation_t *bulk, const bson_t *selector, const mongoc_bulk_remove_opts_t *remove_opts, int32_t limit, bson_error_t *error) /* OUT */ { mongoc_write_command_t command = {0}; mongoc_write_command_t *last; bson_t opts; bool has_collation; bool ret = false; ENTRY; BSON_ASSERT (bulk); BSON_ASSERT (selector); bson_init (&opts); /* allow "limit" in opts, but it must be the correct limit */ if (remove_opts->limit != limit) { bson_set_error (error, MONGOC_ERROR_COMMAND, MONGOC_ERROR_COMMAND_INVALID_ARG, "Invalid \"limit\" in opts: %" PRId32 "." " The value must be %" PRId32 ", or omitted.", remove_opts->limit, limit); GOTO (done); } bson_append_int32 (&opts, "limit", 5, limit); has_collation = !bson_empty (&remove_opts->collation); if (has_collation) { bson_append_document (&opts, "collation", 9, &remove_opts->collation); } if (bulk->commands.len) { last = &_mongoc_array_index ( &bulk->commands, mongoc_write_command_t, bulk->commands.len - 1); if (last->type == MONGOC_WRITE_COMMAND_DELETE) { last->flags.has_collation |= has_collation; last->flags.has_multi_write |= (remove_opts->limit == 0); _mongoc_write_command_delete_append (last, selector, &opts); ret = true; GOTO (done); } } _mongoc_write_command_init_delete ( &command, selector, NULL, &opts, bulk->flags, bulk->operation_id); command.flags.has_collation = has_collation; command.flags.has_multi_write = (remove_opts->limit == 0); _mongoc_array_append_val (&bulk->commands, command); ret = true; done: bson_destroy (&opts); RETURN (ret); }