MONGOC_INDEX_OPT_T(3)
π MONGOC_INDEX_OPT_T(3) π
okay bestie, buckle up β this is the mongoc_index_opt_t page from libmongoc, section 3 of the manual, and it's giving vintage. she's cute, she's deprecated, and she still needs to be understood. let's get into it β¨
π¨ WARNING: Deprecated since version 1.8.0 β see Manage Collection Indexes for alternatives. so likeβ¦ if you're starting something new, maybe don't. but if you're maintaining old code, i gotchu π«Ά
β¨ SYNOPSIS β¨
#include <mongoc/mongoc.h>
typedef struct {
bool is_initialized;
bool background;
bool unique;
const char *name;
bool drop_dups;
bool sparse;
int32_t expire_after_seconds;
int32_t v;
const bson_t *weights;
const char *default_language;
const char *language_override;
mongoc_index_opt_geo_t *geo_options;
mongoc_index_opt_storage_t *storage_options;
const bson_t *partial_filter_expression;
const bson_t *collation;
void *padding[4];
} mongoc_index_opt_t;
look at her. all those fields. the padding[4] at the end is so iconic, honestly β she's reserving space like a girl saving seats at a concert π
πΈ DESCRIPTION πΈ
so this struct? it's the little bag of settings you use to tune one specific index. like, index customization, but make it C.
for what each individual option actually does, go read the createIndexes docs in the MongoDB manual β that's where the real lore lives, i'm not gonna re-explain it here.
β οΈ NOTE: dropDups is deprecated as of MongoDB version 3.0.0. the server just silently ignores this option now β no error, no warning, nothing, it's just out here ghosting you π. and the tea is: unique index builds that use this option will fail if a duplicate value is detected. so like, don't. periodt.
π¦ EXAMPLE π¦
{
bson_t keys;
bson_error_t error;
mongoc_index_opt_t opt;
mongoc_index_opt_geo_t geo_opt;
mongoc_index_opt_init (&opt);
mongoc_index_opt_geo_init (&geo_opt);
bson_init (&keys);
BSON_APPEND_UTF8 (&keys, "location", "2d");
geo_opt.twod_location_min = -123;
geo_opt.twod_location_max = +123;
geo_opt.twod_bits_precision = 30;
opt.geo_options = &geo_opt;
collection = mongoc_client_get_collection (client, "test", "geo_test");
if (mongoc_collection_create_index (collection, &keys, &opt, &error)) {
/* Successfully created the geo index */
}
bson_destroy (&keys);
mongoc_collection_destroy (&collection);
}
see how she inits the options first, sets up the geo params, then builds the index? that's the flow. the /* Successfully created the geo index */ comment is where you get to celebrate π₯
π SEE ALSO π
mongoc_index_opt_geo_tmongoc_index_opt_wt_t
(the other two option structs β the friend group π«Ά)
π AUTHOR π
MongoDB, Inc
π COPYRIGHT π
2009-present, MongoDB, Inc.
okay that's the whole page, you ate that π version 1.30.13, dated Oct 09, 2026 β love her, she's a legacy icon, go forth and index responsibly β¨π
π¦ where this page comes from
- fedora 43: mongo-c-driver-devel 1.30.13-1.fc43 Β· Apache-2.0 AND ISC AND MIT AND Zlib
- fedora 43: mongo-c-driver-devel 1.30.13-1.fc43 Β· Apache-2.0 AND ISC AND MIT AND Zlib
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms