stdx::optional<result::update> collection::update_one(view_or_value filter, view_or_value update, const options::update& options) { options::bulk_write bulk_opts; bulk_opts.ordered(false); if (options.bypass_document_validation()) { bulk_opts.bypass_document_validation(*options.bypass_document_validation()); } if (options.write_concern()) { bulk_opts.write_concern(*options.write_concern()); } class bulk_write bulk_op(bulk_opts); model::update_one update_op(filter, update); if (options.collation()) { update_op.collation(*options.collation()); } if (options.upsert()) { update_op.upsert(*options.upsert()); } bulk_op.append(update_op); auto result = bulk_write(bulk_op); if (!result) { return stdx::nullopt; } return stdx::optional<result::update>(result::update(std::move(result.value()))); }
stdx::optional<result::update> collection::update_one(view_or_value filter, view_or_value update, const options::update& options) { class bulk_write bulk_op(false); model::update_one update_op(filter, update); if (options.upsert()) update_op.upsert(options.upsert().value()); bulk_op.append(update_op); if (options.bypass_document_validation()) bulk_op.bypass_document_validation(*options.bypass_document_validation()); if (options.write_concern()) bulk_op.write_concern(*options.write_concern()); auto result = bulk_write(bulk_op); if (!result) { return stdx::optional<result::update>(); } return stdx::optional<result::update>(result::update(std::move(result.value()))); }
stdx::optional<result::replace_one> collection::replace_one(view_or_value filter, view_or_value replacement, const options::update& options) { options::bulk_write bulk_opts; bulk_opts.ordered(false); if (options.bypass_document_validation()) bulk_opts.bypass_document_validation(*options.bypass_document_validation()); if (options.write_concern()) bulk_opts.write_concern(*options.write_concern()); class bulk_write bulk_op(bulk_opts); model::replace_one replace_op(filter, replacement); if (options.upsert()) replace_op.upsert(options.upsert().value()); bulk_op.append(replace_op); auto result = bulk_write(bulk_op); if (!result) { return stdx::optional<result::replace_one>(); } return stdx::optional<result::replace_one>(result::replace_one(std::move(result.value()))); };