MONGOC_COLLECTION_DELETE_ONE(3)

πŸ’… MONGOC_COLLECTION_DELETE_ONE πŸ’…

okay bestie, welcome to the libmongoc manual page for mongoc_collection_delete_one β€” yes that's the whole manual name, we're not copying the header line, we're living it ✨

This is the function that deletes exactly one document and honestly? she's an icon, she's a legend, and she is the moment πŸ”₯


✨ SYNOPSIS ✨

bool
mongoc_collection_delete_one (mongoc_collection_t *collection,
                              const bson_t *selector,
                              const bson_t *opts,
                              bson_t *reply,
                              bson_error_t *error);

like, look at that signature. no cap, it ate πŸ’…


πŸŽ€ PARAMETERS πŸŽ€

  • collection β€” a mongoc_collection_t. literally the collection you're deleting from, she's the main character here πŸ‘‘
  • selector β€” a bson_t holding the query that matches documents. this is how you tell her which doc you mean 🎯
  • reply β€” a maybe-NULL pointer to overwritable storage for a bson_t that will contain the results. maybe-NULL is so real of her πŸ™ˆ
  • error β€” an optional location for a bson_error_t, or NULL. your choice bestie 🫢

so opts can be NULL, or a BSON document with extra command options, and here's the whole lineup:

  • writeConcern β€” construct a mongoc_write_concern_t and use mongoc_write_concern_append() to add the write concern to opts. see the example code for mongoc_client_write_command_with_opts() πŸ“
  • sessionId β€” first, construct a mongoc_client_session_t with mongoc_client_start_session(). you can begin a transaction with mongoc_client_session_start_transaction(), optionally with a mongoc_transaction_opt_t that overrides the options inherited from collection, and use mongoc_client_session_append() to add the session to opts. see the example code for mongoc_client_session_t 🧚
  • validate β€” construct a bitwise-or of all desired bson_validate_flags_t. set to false to skip client-side validation of the provided BSON documents ⭐
  • comment β€” a bson_value_t specifying the comment to attach to this command. the comment will appear in log messages, profiler output, and currentOp output. requires MongoDB 4.4 or later πŸ¦‹
  • collation β€” configure textual comparisons. see Setting Collation Order, and the MongoDB Manual entry on Collation. collation requires MongoDB 3.2 or later, otherwise an error is returned πŸ’€
  • hint β€” a document or string that specifies the index to use to support the query predicate πŸ”
  • let β€” a BSON document consisting of any number of parameter names, each followed by definitions of constants in the MQL Aggregate Expression language 🌸

πŸ’– DESCRIPTION πŸ’–

this function removes at most one document in the given collection that matches selector. one. single. document. she's not greedy, she's discerning πŸ’…

if you need to delete all the matching documents, use mongoc_collection_delete_many() β€” different function, different vibe, go look her up πŸŽ€

if you pass a non-NULL reply, it gets filled out with the field "deletedCount". and if there's a server error then reply contains either a "writeErrors" array with one subdocument, or a "writeConcernErrors" array. either way, that reply must be freed with bson_destroy(). don't forget, bestie, that's a memory leak waiting to happen 😭


πŸ”₯ ERRORS πŸ”₯

errors are propagated via the error parameter. that's it, that's the whole section, she's lowkey mysterious about it πŸ™ˆ


🌈 RETURNS 🌈

returns true if successful. returns false and sets error if there are invalid arguments or a server or network error. simple as that, no cap ✨


πŸ‘‘ AUTHOR πŸ‘‘

MongoDB, Inc πŸ’œ


2009-present, MongoDB, Inc. β€” protect her at all costs 🫢


and that's the page, babes!! sign-off time: this was libmongoc version 2.5.6, dated Oct 09, 2026, and honestly? she's giving timeless. go delete exactly one document, drink some water, and remember that bson_destroy() is self care πŸ’–πŸŽ€πŸ¦‹πŸ“

πŸ“¦ where this page comes from