static void _mongoc_bulk_operation_update_append ( mongoc_bulk_operation_t *bulk, const bson_t *selector, const bson_t *document, const mongoc_bulk_update_opts_t *update_opts, const bson_t *extra_opts) { mongoc_write_command_t command = {0}; mongoc_write_command_t *last; bson_t opts; bool has_collation; bson_init (&opts); bson_append_bool (&opts, "upsert", 6, update_opts->upsert); bson_append_bool (&opts, "multi", 5, update_opts->multi); has_collation = !bson_empty (&update_opts->collation); if (has_collation) { bson_append_document (&opts, "collation", 9, &update_opts->collation); } if (extra_opts) { bson_concat (&opts, extra_opts); } if (bulk->commands.len) { last = &_mongoc_array_index ( &bulk->commands, mongoc_write_command_t, bulk->commands.len - 1); if (last->type == MONGOC_WRITE_COMMAND_UPDATE) { last->flags.has_collation |= has_collation; last->flags.has_multi_write |= update_opts->multi; _mongoc_write_command_update_append (last, selector, document, &opts); bson_destroy (&opts); return; } } _mongoc_write_command_init_update ( &command, selector, document, &opts, bulk->flags, bulk->operation_id); command.flags.has_collation = has_collation; command.flags.has_multi_write = update_opts->multi; _mongoc_array_append_val (&bulk->commands, command); bson_destroy (&opts); }
void _mongoc_write_command_init_update_idl (mongoc_write_command_t *command, const bson_t *selector, const bson_t *update, const bson_t *opts, int64_t operation_id) { mongoc_bulk_write_flags_t flags = MONGOC_BULK_WRITE_FLAGS_INIT; ENTRY; BSON_ASSERT (command); _mongoc_write_command_init_bulk ( command, MONGOC_WRITE_COMMAND_UPDATE, flags, operation_id, NULL); _mongoc_write_command_update_append (command, selector, update, opts); EXIT; }
void mongoc_bulk_operation_update (mongoc_bulk_operation_t *bulk, const bson_t *selector, const bson_t *document, bool upsert) { bool multi = true; mongoc_write_command_t command = { 0 }; bson_iter_t iter; mongoc_write_command_t *last; BSON_ASSERT (bulk); BSON_ASSERT (selector); BSON_ASSERT (document); ENTRY; if (bson_iter_init (&iter, document)) { while (bson_iter_next (&iter)) { if (!strchr (bson_iter_key (&iter), '$')) { MONGOC_WARNING ("%s(): update only works with $ operators.", BSON_FUNC); EXIT; } } } if (bulk->commands.len) { last = &_mongoc_array_index (&bulk->commands, mongoc_write_command_t, bulk->commands.len - 1); if (last->type == MONGOC_WRITE_COMMAND_UPDATE) { _mongoc_write_command_update_append (last, selector, document, upsert, multi); EXIT; } } _mongoc_write_command_init_update (&command, selector, document, upsert, multi, bulk->flags, bulk->operation_id); _mongoc_array_append_val (&bulk->commands, command); EXIT; }
void _mongoc_write_command_init_update (mongoc_write_command_t *command, /* IN */ const bson_t *selector, /* IN */ const bson_t *update, /* 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); BSON_ASSERT (update); _mongoc_write_command_init_bulk ( command, MONGOC_WRITE_COMMAND_UPDATE, flags, operation_id, NULL); _mongoc_write_command_update_append (command, selector, update, opts); EXIT; }
void mongoc_bulk_operation_replace_one (mongoc_bulk_operation_t *bulk, const bson_t *selector, const bson_t *document, bool upsert) { mongoc_write_command_t command = { 0 }; size_t err_off; mongoc_write_command_t *last; int flags = BSON_VALIDATE_DOT_KEYS|BSON_VALIDATE_DOLLAR_KEYS; BSON_ASSERT (bulk); BSON_ASSERT (selector); BSON_ASSERT (document); ENTRY; if (!bson_validate (document, (bson_validate_flags_t)flags, &err_off)) { MONGOC_WARNING ("%s(): replacement document may not contain " "$ or . in keys. Ignoring document.", BSON_FUNC); EXIT; } if (bulk->commands.len) { last = &_mongoc_array_index (&bulk->commands, mongoc_write_command_t, bulk->commands.len - 1); if (last->type == MONGOC_WRITE_COMMAND_UPDATE) { _mongoc_write_command_update_append (last, selector, document, upsert, false); EXIT; } } _mongoc_write_command_init_update (&command, selector, document, upsert, false, bulk->flags, bulk->operation_id); _mongoc_array_append_val (&bulk->commands, command); EXIT; }
void _mongoc_write_command_init_update (mongoc_write_command_t *command, /* IN */ const bson_t *selector, /* IN */ const bson_t *update, /* IN */ bool upsert, /* IN */ bool multi, /* IN */ mongoc_bulk_write_flags_t flags) /* IN */ { ENTRY; BSON_ASSERT (command); BSON_ASSERT (selector); BSON_ASSERT (update); command->type = MONGOC_WRITE_COMMAND_UPDATE; command->documents = bson_new (); command->n_documents = 0; command->flags = flags; command->hint = 0; _mongoc_write_command_update_append (command, selector, update, upsert, multi); EXIT; }