Hi @katlv_zheng
Welcome to MongoDB forums!
You need to convert the _id field of your document to a bsoncxx::types::bson_value::view using the bsoncxx::types::bson_value::view_or_value constructor. I have shared sample code below.
// ---------------UPLOAD---------------//
// "sample_gridfs_file" is the name of the GridFS file stored on the server.
auto uploader = bucket.open_upload_stream("sample_gridfs_file");
// ASCII for "HelloWorld"
std::uint8_t bytes[10] = {72, 101, 108, 108, 111, 87, 111, 114, 108, 100};
// Write 50 bytes to the file.
for (auto i = 0; i < 5; ++i) {
uploader.write(bytes, 10);
}
auto result = uploader.close();
// // ---------------DELETE---------------//
// Delete the uploaded file by using the id.
// "id" can be reused directly, but construct a document for the sake of example.
bsoncxx::types::bson_value::view id = result.id();
bsoncxx::document::value doc_value = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("_id", id));
bsoncxx::document::view doc_view = doc_value.view();
bsoncxx::types::bson_value::view_or_value id_value {doc_view["_id"].get_value()};
// Pass the id to the delete_file
bucket.delete_file(id_value);