MONGOC_COLLECTION_DELETE(3)

πŸ’… MONGOC_COLLECTION_DELETE(3) β€” the libmongoc girlie's guide

okay bestie, come sit with me, we need to talk about mongoc_collection_delete 🫢

⚠️ WARNING, and I mean it, no cap: this one is deprecated since version 1.9.0. Like, it's giving "still in the group chat but never replies". Please use mongoc_collection_remove(), mongoc_collection_delete_one() or mongoc_collection_delete_many() instead. Those are the main characters now. πŸ‘‘

✨ SYNOPSIS ✨

bool
mongoc_collection_delete (mongoc_collection_t *collection,
                          mongoc_delete_flags_t flags,
                          const bson_t *selector,
                          const mongoc_write_concern_t *write_concern,
                          bson_error_t *error);

that's the whole vibe. five args, one bool, let's get into it πŸ’–


πŸŽ€ PARAMETERS πŸŽ€

  • collection β€” a mongoc_collection_t. the collection we're doing all this on, obviously πŸ’
  • flags β€” a mongoc_delete_flags_t. yes it's a whole type, and yes it matters, keep reading πŸ‘€
  • selector β€” a bson_t holding the query that matches the documents you wanna delete. this is your hit list, basically 🎯
  • write_concern β€” a mongoc_write_concern_t, or NULL. your choice bestie, NULL is valid πŸ™ˆ
  • error β€” an optional spot for a bson_error_t, or NULL. optional!! you can absolutely pass NULL and live your truth ✨

πŸ¦‹ DESCRIPTION πŸ¦‹

so this function shall delete documents in the given collection that match selector. simple, iconic, exactly what it says on the tin πŸ’…

now here's the thing β€” the bson selector is not validated. not even a little. it's just passed along as appropriate to the server. so compatibility and errors? that's a you problem, and by "you" I mean the appropriate server documentation. go read it, I'm begging 😭

and if you wanna limit your deletes to a single document β€” like, just the one, not the whole friend group β€” provide MONGOC_DELETE_SINGLE_REMOVE in flags. periodt 🌸


πŸ’€ ERRORS πŸ’€

errors get propagated via the error parameter. that's the whole section. she's short but she's honest 🫢


πŸ”₯ RETURNS πŸ”₯

returns true if successful. returns false and sets error if there are invalid arguments, or a server or network error. so like, false is never a mystery, the error will tell you what's up 🧚

πŸ’€ also: a write concern timeout or a write concern error counts as a failure. yes, even if it feels like it kind of worked. it did not. it's a fail. don't argue with me πŸ’…

πŸ‘‘ AUTHOR πŸ‘‘

MongoDB, Inc. the original icons. 🫑


2009-present, MongoDB, Inc. β€” protected, babes, don't be weird about it πŸ’œ


and that's the whole page, bestie!! this was libmongoc version 1.30.13, dated Oct 09, 2026, and the page you just read is MONGOC_COLLECTION_DELETE(3). now go use mongoc_collection_remove() like I told you πŸ˜­πŸ’– bye!! πŸŽ€

πŸ“¦ where this page comes from