MONGOC_BULKWRI...PTS_SET_UPSERT(3)

🌸 mongoc_bulkwrite_replaceoneopts_set_upsert 🌸

okay bestie, so this little cutie lives in libmongoc (yes, the MongoDB C driver, we stan) and it's genuinely one of those tiny options that changes everything about how your replace-one op behaves. it's giving "small but mighty" energy fr fr. πŸ’…


✨ SYNOPSIS ✨

void
mongoc_bulkwrite_replaceoneopts_set_upsert (mongoc_bulkwrite_replaceoneopts_t *self, bool upsert);

so it takes a mongoc_bulkwrite_replaceoneopts_t *self (the options struct, obvi) plus a bool upsert, and returns void β€” no return value, no drama, no notes. πŸŽ€


πŸ’– DESCRIPTION πŸ’–

Okay so here's the tea: if upsert is true, then when nothing matches your query, it just... creates a brand new document. no match? no problem. it manifests one. ✨ iconic behavior honestly.

And here's the crucial part β€” if you never call this function, the upsert option isn't sent at all. like, it doesn't get defaulted on the client side and quietly shipped off; it's just not there. and the server's own default value is false. so if you want the magic insert-if-missing vibe, you have to say so. no assumptions, bestie. πŸ™ˆ

lowkey important: <cyan>false</cyan> and "never called" behave the same way in the end β€” no upsert for you β€” but the wire differs because one sends nothing and the other sends false. the manpage is clear that the option is simply not sent when you don't call it, so don't go telling people it defaults client-side. 😭

🫢 AUTHOR 🫢

MongoDB, Inc β€” they made this, we love them for it, periodt. πŸ’œ


2009-present, MongoDB, Inc. β€” all the rights, all the years, all the slay. πŸ‘‘


<div>and that's the whole page, bestie!! this was version 2.5.6, dated Oct 09, 2025 β€” go forth and upsert responsibly πŸ¦‹βœ¨</div>

πŸ“¦ where this page comes from