MONGOC_DATABA...ATE_COLLECTION(3)

✨ mongoc_database_create_collection(3) ✨

okay so bestie, welcome to libmongoc β€” yes, the manual is literally called that, and yes, this page is your whole guide to making a brand-new collection appear out of thin air. it's giving creation energy. πŸ¦‹


🌸 SYNOPSIS 🌸

mongoc_collection_t *
mongoc_database_create_collection (mongoc_database_t *database,
                                   const char *name,
                                   const bson_t *opts,
                                   bson_error_t *error);

like, that's the whole vibe. four args, one gorgeous little collection at the end. πŸ’–


πŸŽ€ PARAMETERS πŸŽ€

  • database: A mongoc_database_t. the database you're spawning this baby inside, obviously.
  • name: The name of the new collection. pick something cute, you're stuck with it.
  • opts: An optional bson_t for opts to the create command. optional optional, so you can pass nothing and still slay.
  • error: A location for a bson_error_t or NULL. if you don't care about the tea when things go wrong, just pass NULL and move on. πŸ™ˆ

πŸ¦‹ DESCRIPTION πŸ¦‹

so this function literally creates a mongoc_collection_t from the given mongoc_database_t. iconic behavior, no notes. πŸ‘‘

if no write concern is provided in opts, the database's write concern is used. so it's not just doing whatever β€” it inherits the family's settings, main character energy by association. ✨

the encryptedFields document in opts may be used to create a collection used for Queryable Encryption. yes that's a real thing, yes it's a whole mood, yes the capital letters are load-bearing. πŸ”₯

for a list of all options, see the MongoDB Manual entry on the create command. don't come for me, the manual is literally right there. iykyk. πŸ“–


πŸ’€ ERRORS πŸ’€

Errors are propagated via the error parameter. so if something goes wrong, it does not just silently ghost you β€” it tells error, and error tells you. 🫢


⭐ RETURNS ⭐

this function returns a newly allocated mongoc_collection_t upon success, NULL upon failure and error is set. periodt. if you get NULL, go check error immediately, don't just sit there like 😭.

also friendly reminder that "newly allocated" means you own it β€” free it when you're done, bestie, or it's a leak. πŸ’…

🌈 AUTHOR 🌈

MongoDB, Inc


2009-present, MongoDB, Inc.


okay that's the whole page, you ate that. πŸ“

cute little sign-off: this gorgeous piece of documentation comes from libmongoc, version 2.5.6, dated Oct 09, 2026 β€” so go forth, create collections, and free your memory. mwah. πŸ§šπŸ’–

πŸ“¦ where this page comes from