BSON_READER_READ(3)

πŸ’… BSON_READER_READ(3) β€” the libbson girlies present: reading ur docs one at a time ✨

okay so bestie, welcome to bson_reader_read from libbson (section 3 of the manual, very official, very cunty). this is the little function that grabs the next document for you off a stream. she's simple, she's reliable, she's giving main character energy. let's get into it πŸŽ€


✨ SYNOPSIS ✨

const bson_t *
bson_reader_read (bson_reader_t *reader, bool *reached_eof);

that's the whole vibe. two args in, one const bson_t * out. iconic πŸ’…


🌸 PARAMETERS 🌸

  • reader β€” a bson_reader_t. the reader bestie in question, the one doing the reading, the whole point fr fr 🫢
  • reached_eof β€” a UNKNOWN. yes. that's genuinely what the docs say. we are not making this up, that placeholder just never got filled in 😭 she's mysterious, she's a mystery, she is unknown πŸ’€

πŸ¦‹ DESCRIPTION πŸ¦‹

so the bson_reader_read() function shall read the next document from the underlying file-descriptor or buffer. that's the job. that's what she does. no cap.

if there are no further documents, or a failure was detected, then NULL is returned. simple as that, bestie. null means nothing came back πŸ«₯

if we reached the end of the sequence, reached_eof is set to true. end of the line, end of the scroll, end of the era πŸ’œ

⚠️ to detect an error, check for NULL and reached_of is false. and yes, the docs literally say reached_of there β€” that's a typo era moment, but we're telling you exactly what the page says so nothing gets lost πŸ™ˆ

⭐ RETURNS ⭐

a bson_t that should not be modified or freed. like, do not touch. do not free. do not edit. hands off the artifact, she's not yours, she belongs to the reader πŸ‘‘


πŸ”₯ EXAMPLE πŸ”₯

here's the actual loop, copied exactly, because we do not play with code:

const bson_t *doc;
bool reached_eof = false;

while ((doc = bson_reader_read (reader, &reached_eof))) {
   /* do something */
}

if (!reached_eof) {
   fprintf (stderr, "Failed to read all documents.\n");
}

see how it loops until bson_reader_read hands back NULL, and then it checks reached_eof to know whether that NULL was a cute little end-of-stream or a genuine failure? that's the pattern, that's the move, that's the whole slay 🌈


🧚 AUTHOR 🧚

MongoDB, Inc β€” yeah, they made this. kings, honestly πŸ‘‘


2009-present, MongoDB, Inc. all the years, all the rights, all the vibes πŸ’–


okay that's the page!! big mwah to libbson, this is version 2.5.6, dated Oct 09, 2026 β€” go read some documents bestie, and remember: NULL + reached_eof == false means something went wrong, so check it 😀✨ πŸ¦‹

πŸ“¦ where this page comes from