MongoDB - CSFLE - Unrecognized pipeline stage name: '$search'

problem

I'm having a MongoDB setup with CSFLE (Client-Side Field Level Encryption) enabled and I want to use the more advanced and recommended Atlas Search for full-text search.

I'm using the $search aggregation stage, but keep getting the following error message:

MongoDB.Driver.Encryption.MongoEncryptionException: Encryption related exception: Command aggregate failed: Unrecognized pipeline stage name: '$search'.

solution

It turns out the $search stage is not supported with CSFLE, it's not in the list of supported aggregation stages - https://www.mongodb.com/docs/manual/core/csfle/reference/supported-operations/#supported-aggregation-stages

There are two workarounds I could think of:

  1. Don't use the Atlas Search and use instead the basic Find with filters in MongoDB, employing regular expressions such as .*{searchValue}.*
  2. If possible, use Atlas Search without CSFLE. For some use cases, when you don't have to search by fields that are encrypted, you can use an unencrypted client that ignores the encrypted fields.
Gravatar
Author: Dan Dumitru
Last Edit: September 28, 2022
Last Edit September 28, 2022
Created September 28, 2022
Views 39
Tags
MongoDB

Join in!

I'm building here a library of useful solutions to software development problems.

If you like this project, create an account or add a bookmark, then come back here to write a post yourself when you run into something that might be useful to others...

>> read more

Your Comment

Feel free to post additional info or improvement suggestions.
preview
Optional, never shown, displays gravatar.

Formatting Tips

This editor uses Markdown to easily add code in your posts.

Triple backticks for full line(s) of code (or indent 4 spaces)

```
let foo = 'bar';
```

[link text](http://a.com)

*italic* **bold**

More Tips