Using v1.9.0 of the C# driver (latest at time of writing) with MongoDB 2.6.0
What is the best way currently to create a text index on a collection, via the C# driver?
From what I could tell, it's not possible via MongoCollection.CreateIndex
? So currently creating it using MongoDatabase.Eval like so:
Database.Eval(new EvalArgs { Code = "function(){db.dummycollection.ensureIndex({\"$**\" : \"text\"},{name:\"TextIndex\"});}"
Am I missing something / is there a better way?
Just verified that the following works with the 1.9.0 C# driver and MongoDB 2.6.0-rc2:
MongoCollection.CreateIndex(new IndexKeysDocument("Markdown", "text"));
(this also works with older drivers)
EDIT
djch's answer shows the better way to do it using the 1.9 driver because it can also be used stronly-typed, e.g.:
MongoCollection.CreateIndex(IndexKeys<MyClass>.Text(p => p.Markdown));
This should work:
collection.EnsureIndex(IndexKeys.Text("a", "b").Ascending("c"), IndexOptions.SetTextLanguageOverride("idioma").SetName("custom").SetTextDefaultLanguage("spanish"));
https://jira.mongodb.org/browse/CSHARP-874
https://github.com/mongodb/mongo-csharp-driver/commit/1e7db3bedb3bee1b0ccecdb5f8ff39854526213a
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With