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β abson_reader_t. the reader bestie in question, the one doing the reading, the whole point fr fr π«Άreached_eofβ aUNKNOWN. 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 forNULLandreached_ofis false. and yes, the docs literally sayreached_ofthere β 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 π
π COPYRIGHT π
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
- epel 10: libbson-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