MONGOC_GRIDFS...STREAM_WITH_ID(3)
π¦ MONGOC_GRIDFS...STREAM_WITH_ID(3) π¦
okay bestie so this one is from libmongoc and it's lowkey the "i already know the id i want" version of uploading a file into GridFS π
β¨ SYNOPSIS β¨
bool
mongoc_gridfs_bucket_upload_from_stream_with_id (mongoc_gridfs_bucket_t *bucket,
const bson_value_t *file_id,
const char *filename,
mongoc_stream_t *source,
const bson_t *opts,
bson_error_t *error);
like, that's the whole vibe. one function, six args, slay π
πΈ PARAMETERS πΈ
bucketβ amongoc_gridfs_bucket_t. your bucket. your home. your main character bucket πfile_idβ abson_value_tthat says what the id of the created file is gonna be. yes you pick it, that's literally the whole point of_with_idπ«Άfilenameβ the name of the file you're creating. the label. the nameplate. the β¨brandingβ¨sourceβ amongoc_stream_tthat's the source of the data you're uploading. it's the straw, the file is the drink πoptsβ abson_torNULL. no thoughts, head empty,NULLis fine πerrorβ abson_error_tto receive any error, orNULLif you don't wanna hear about it π
so opts can be NULL, or it can be a BSON document with extra command options:
chunkSizeBytesβ anint32chunk size to use for this file. it overrides thechunkSizeBytesset onbucket. no cap, this one wins π₯metadataβ abson_trepresenting metadata to include with the file. put your little extra facts in there π
π§ DESCRIPTION π§
so what it does: it reads from the source stream and writes to a new file in GridFS. that's it. that's the girldinner π
if you want libmongoc to generate an id for you instead of handing it one, use mongoc_gridfs_bucket_upload_from_stream() instead. that's the sibling. the equally iconic sibling π
it reads from the source stream using mongoc_stream_read() until the return value indicates end-of-file. that's how it knows you're done. it just keeps reading until the stream says "that's all bestie" π
ok this part matters: the source stream is not closed after callingmongoc_gridfs_bucket_upload_from_stream(). you gotta callmongoc_stream_close()after. it's giving "i'm not gonna do it for you" energy. do your own cleanup, queen π§Ήβ¨
β RETURNS β
True if the operation succeeded. False otherwise β and in that case it sets error. so like, check it. always check it. π
π SEE ALSO:
mongoc_stream_file_new()andmongoc_stream_file_new_for_path()β these are the icons you can use to create a source stream from a file. very much "turn a file into a stream" behavior, iykyk π
π AUTHOR π
MongoDB, Inc β the collective. the group chat. the whole team π
π COPYRIGHT π
2009-present, MongoDB, Inc. periodt.
ok that's the whole page, mwah π version 2.5.6, dated Oct 09, 2026, from the libmongoc girlies β now go upload something with a very deliberate id, you absolute legend π¦β¨
π¦ where this page comes from
- epel 10: mongo-c-driver-devel 2.5.6-1.el10_3 Β· Apache-2.0 AND ISC AND MIT AND Zlib
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms