BSON_APPEND_TIMESTAMP(3)

πŸ’… BSON_APPEND_TIMESTAMP πŸ’…

okay so bestie, welcome to the libbson girlies' corner of the manual β€” this one's about BSON_APPEND_TIMESTAMP, and it's lowkey iconic for how much it is not the date-time function. buckle up πŸŽ€


✨ SYNOPSIS ✨

the macro version, for when you're feeling efficient:

#define BSON_APPEND_TIMESTAMP(b, key, val, inc) \
   bson_append_timestamp (b, key, (int) strlen (key), val, inc)

and the real function underneath, doing the actual work:

bool
bson_append_timestamp (bson_t *bson,
                       const char *key,
                       int key_length,
                       uint32_t timestamp,
                       uint32_t increment);

🌸 PARAMETERS 🌸

  • bson β€” a bson_t. that's the doc you're stuffing things into, bestie 🫢
  • key β€” an ASCII C string with the name of the field. cute, short, ASCII.
  • key_length β€” how long key is, in bytes. orrr you can pass -1 and let it figure the length out with strlen(). main character energy honestly ✨
  • timestamp β€” a uint32_t. yes, exactly that type, don't come at me.
  • increment β€” another uint32_t. it's a whole separate field, we'll get to it πŸ’…

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so FIRST thing's first, and I need you to really hear me on this one: this function is not similar in functionality to bson_append_date_time(). like, not even a little. they are different girls, they serve different purposes, do not confuse them πŸ™ˆ

timestamp elements are different in that they include only second precision and an increment field. that's it. that's the whole vibe. no fancy sub-second anything, just seconds plus that little increment riding along πŸ’€

they are primarily used for intra-MongoDB server communication. iykyk β€” it's an internal thing, it's giving "backstage pass only" 🎫

and the actual deed: bson_append_timestamp() shall append a new element of type BSON_TYPE_TIMESTAMP. slay ✨


⭐ RETURNS ⭐

returns true if the operation was applied successfully β€” we love a happy ending πŸ’–

⚠️ but heads up: the function will fail if appending the value grows bson larger than INT32_MAX. like, that's the line, and we do not cross it. 😭

πŸ‘‘ AUTHOR πŸ‘‘

MongoDB, Inc β€” icons only, no notes πŸ’…


2009-present, MongoDB, Inc. β€” a long and storied reign, periodt πŸ‘‘


and that's the page, bestie! go forth and append those timestamps, and remember: second precision only, increment included, and absolutely not bson_append_date_time(). mwah πŸ“

β€” signed with love from the libbson 2.5.6 girlies, dated Oct 09, 2026 πŸ§šβ€β™€οΈπŸ’œ

πŸ“¦ where this page comes from