---
name: "mongoc_client_encryption_encrypt_expression"
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_client_encryption_encrypt_expression"
---

# mongoc\_client\_encryption\_encrypt\_expression(3)

## SYNOPSIS

```
bool
mongoc_client_encryption_encrypt_expression (
   mongoc_client_encryption_t *client_encryption,
   const bson_t *expr,
   mongoc_client_encryption_encrypt_opts_t *opts,
   bson_t *expr_out,
   bson_error_t *error);
```

Added in version 1.24.0.

Encrypts a Match Expression or Aggregate Expression to query a range index.

To query with a **Range** encrypted payload, use a *mongoc\_client\_t* configured with *mongoc\_auto\_encryption\_opts\_t*. The *mongoc\_auto\_encryption\_opts\_t* may be configured to bypass query analysis with *mongoc\_auto\_encryption\_opts\_set\_bypass\_query\_analysis()*. The *mongoc\_auto\_encryption\_opts\_t* must not be configured to bypass automatic encryption with *mongoc\_auto\_encryption\_opts\_set\_bypass\_auto\_encryption()*.

To query with a **Range** payload, **expr** must be one of the following forms:

- 1\.

  A Match Expression of the following form:

  ```
  // $gt may also be $gte. $lt may also be $lte.
  // Can include one of $gt/$gte/$lt/$lte. It is not required to include both.
  {"$and": [{"<field>": {"$gt": "<value1>"}}, {"<field>": {"$lt": "<value2>" }}]}
  ```

- 2\.

  An Aggregation Expression of this form:

  ```
  // $gt may also be $gte. $lt may also be $lte
  // Can include one of $gt/$gte/$lt/$lte. It is not required to include both.
  {"$and": [{"$gt": ["<fieldpath>", "<value1>"]}, {"$lt": ["<fieldpath>", "<value2>"]}]
  ```

## PARAMETERS

- •

  **client\_encryption**: A *mongoc\_client\_encryption\_t*

- •

  **expr**: The expression to encrypt.

- •

  **opts**: A *mongoc\_client\_encryption\_encrypt\_opts\_t*.

- •

  **expr\_out**: A *bson\_t* for the resulting encrypted expression. **expr\_out** is always initialized (even on failure). Caller must call *bson\_destroy()* to free.

- •

  **error**: A *bson\_error\_t* set on failure.

## RETURNS

Returns **true** if successful. Returns **false** and sets **error** otherwise.

**SEE ALSO:**

```
mongoc_client_encryption_encrypt_opts_t
```

```
mongoc_client_enable_auto_encryption()
```

```
mongoc_client_decryption_decrypt()
```

## AUTHOR

MongoDB, Inc

## COPYRIGHT

2009-present, MongoDB, Inc.
