如何将嵌套字段添加到 MongoDB 中的文本索引?
How do you add nested fields to a text index in MongoDB?
我在将嵌套字段添加到 MongoDB 中的文本索引时遇到问题。
下面的代码将顶层的字符串字段正确添加到文本索引。我尝试添加的两个嵌套字段 "contentright" 和 "contentfooterhead" 已添加但索引不正确。
var keys = {"name", "subject", "contentright", "contentfooterhead"};
var indexKeys = new IndexKeysBuilder();
indexKeys.Text(keys);
var options = new IndexOptionsBuilder();
options.SetName("testIndex");
options.SetBackground(true);
collection.CreateIndex(indexKeys, options);
这是我的文本索引在代码为 运行:
后的样子
如果我运行
indexKeys.TextAll();
相当于
的索引
"$**": "text"
所有字段都已编入索引,但我不想全部添加。
使用dot notation。嵌套字段的路径是 Con.contentright
和 Con.contentfooterhead
.
我在将嵌套字段添加到 MongoDB 中的文本索引时遇到问题。
下面的代码将顶层的字符串字段正确添加到文本索引。我尝试添加的两个嵌套字段 "contentright" 和 "contentfooterhead" 已添加但索引不正确。
var keys = {"name", "subject", "contentright", "contentfooterhead"};
var indexKeys = new IndexKeysBuilder();
indexKeys.Text(keys);
var options = new IndexOptionsBuilder();
options.SetName("testIndex");
options.SetBackground(true);
collection.CreateIndex(indexKeys, options);
这是我的文本索引在代码为 运行:
后的样子如果我运行
indexKeys.TextAll();
相当于
的索引"$**": "text"
所有字段都已编入索引,但我不想全部添加。
使用dot notation。嵌套字段的路径是 Con.contentright
和 Con.contentfooterhead
.