MONGOC_DATABASE_SET_READ_PREFS(3)

πŸ’… MONGOC_DATABASE_SET_READ_PREFS(3) πŸ’…

okay so bestie, welcome to libmongoc β€” yes that's the C driver for MongoDB and yes we're about to make your database read from exactly where you tell it to. no cap, this one's actually simple and it slays 🫢


✨ SYNOPSIS ✨

void
mongoc_database_set_read_prefs (mongoc_database_t *database,
                                const mongoc_read_prefs_t *read_prefs);

🌸 what it even does 🌸

This function sets the default read preferences to use on operations performed with database. and like β€” the important part β€” collections created with mongoc_database_get_collection() after this call will inherit these read preferences. so you're basically setting the vibe for everything that comes next, iykyk πŸ’«

The global default is MONGOC_READ_PRIMARY: if the client is connected to a replica set it reads from the primary, otherwise it reads from the current MongoDB server. that's the out-of-the-box behavior, no notes, it just works πŸŽ€

Please see the MongoDB website for a description of Read Preferences. (fr fr, go read it, it's giving essential context 🌈)


πŸ¦‹ PARAMETERS πŸ¦‹

  • database: A mongoc_database_t. the database we're setting the vibe for πŸ’œ
  • read_prefs: A mongoc_read_prefs_t. the read preferences themselves, freshly handed over πŸ‘‘

🧚 AUTHOR 🧚

MongoDB, Inc β€” iconic, legendary, no further questions πŸ’…

2009-present, MongoDB, Inc. β€” protect it, respect it, it's theirs 🫢


lowkey a public service announcement: this just sets the default on database β€” it doesn't retroactively change collections you already grabbed. timing matters, bestie ⏰

and that's the whole page, bestie β€” you ate πŸ’– signing off from libmongoc version 2.5.6, dated Oct 09, 2026 β€” see you in the next manpage, mwah πŸ˜­πŸŽ€

πŸ“¦ where this page comes from