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 β€” a mongoc_gridfs_bucket_t. your bucket. your home. your main character bucket πŸ‘‘
  • file_id β€” a bson_value_t that 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 β€” a mongoc_stream_t that's the source of the data you're uploading. it's the straw, the file is the drink πŸ“
  • opts β€” a bson_t or NULL. no thoughts, head empty, NULL is fine 😌
  • error β€” a bson_error_t to receive any error, or NULL if you don't wanna hear about it πŸ™ˆ

so opts can be NULL, or it can be a BSON document with extra command options:

  • chunkSizeBytes β€” an int32 chunk size to use for this file. it overrides the chunkSizeBytes set on bucket. no cap, this one wins πŸ”₯
  • metadata β€” a bson_t representing 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 calling mongoc_gridfs_bucket_upload_from_stream(). you gotta call mongoc_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() and mongoc_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 πŸ‘‘

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