JohnD91
JohnD91

Reputation: 583

How do you create a full text search for all text fields in a mongo collection in the c# driver?

I feel like this should be really simple, yet I've had a google and can't find exactly what I'm looking for.

I can apply the following code in the mongo console:

db.collection.createIndex( { "$**": "text" } )

and I'll get a full text index on all text fields in my collection. How do I achieve this same result on a given collection in the mongo c# driver ?

Upvotes: 1

Views: 376

Answers (1)

Dĵ ΝιΓΞΗΛψΚ
Dĵ ΝιΓΞΗΛψΚ

Reputation: 5669

you can create a wildcard text index with the following.

     collection.Indexes.CreateOne(
         new CreateIndexModel<MyType>(
             Builders<MyType>.IndexKeys.Text("$**")));

Upvotes: 1

Related Questions