---
name: "mongoc_collection_create_index_with_opts"
section: "3"
platform: "linux"
package: "libmongoc-doc"
version: "1.30.4-1+deb13u3"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/mongoc_collection_create_index_with_opts"
---

# mongoc\_collection\_create\_index\_with\_opts(3)

**WARNING:**

Deprecated since version 1.8.0: See *Manage Collection Indexes* for alternatives.

## SYNOPSIS

```
bool
mongoc_collection_create_index_with_opts (mongoc_collection_t *collection,
                                          const bson_t *keys,
                                          const mongoc_index_opt_t *index_opts,
                                          const bson_t *command_opts,
                                          bson_t *reply,
                                          bson_error_t *error);
```

## PARAMETERS

- •

  **collection**: A *mongoc\_collection\_t*.

- •

  **keys**: A *bson\_t*.

- •

  **index\_opts**: A mongoc\_index\_opt\_t.

- •

  **reply**: A maybe-**NULL** pointer to *overwritable storage* for a *bson\_t* to contain the results.

- •

  **error**: An optional location for a *bson\_error\_t* or **NULL**.

**command\_opts** may be NULL or a BSON document with additional command options:

- •

  **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*.

## DESCRIPTION

This function will request the creation of a new index.

This function will use the **createIndexes** command. The server's reply is stored in **reply**.

If no write concern is provided in **command\_opts**, the collection's write concern is used.

See *mongoc\_index\_opt\_t* for options on creating indexes.

## ERRORS

Errors are propagated via the **error** parameter.

## RETURNS

Returns **true** if successful. Returns **false** and sets **error** if there are invalid arguments or a server or network error.

**reply** is always initialized and must be destroyed with *bson\_destroy()*. If the server is running an obsolete version of MongoDB then **reply** may be empty, though it will still be initialized.

## AUTHOR

MongoDB, Inc

## COPYRIGHT

2009-present, MongoDB, Inc.
