通过 C# 驱动程序在 MongoDB 集合上创建文本索引的最佳方法 [英] Best way to create a text index on a MongoDB collection via C# driver

查看:51
本文介绍了通过 C# 驱动程序在 MongoDB 集合上创建文本索引的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 MongoDB 2.6.0 中使用 C# 驱动程序的 v1.9.0(在撰写本文时为最新版本)

Using v1.9.0 of the C# driver (latest at time of writing) with MongoDB 2.6.0

目前通过 C# 驱动程序在集合上创建文本索引的最佳方法是什么?

What is the best way currently to create a text index on a collection, via the C# driver?

据我所知,不可能通过 MongoCollection.CreateIndex 实现?所以目前使用 MongoDatabase.Eval 创建它,如下所示:

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?

推荐答案

这应该有效:

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/提交/1e7db3bedb3bee1b0ccecdb5f8ff39854526213a

这篇关于通过 C# 驱动程序在 MongoDB 集合上创建文本索引的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆