当元素数组中的数组包含应与我的搜索匹配的文本时,我无法检索文档。
以下是两个示例文档:
{
_id: ...,
'foo': [
{
'name': 'Thing1',
'data': {
'text': ['X', 'X']
}
},{
'name': 'Thing2',
'data': {
'text': ['X', 'Y']
}
}
]
}
{
_id: ...,
'foo': [
{
'name': 'Thing3',
'data': {
'text': ['X', 'X']
}
},{
'name': 'Thing4',
'data': {
'text': ['X', 'Y']
}
}
]
}
通过使用以下查询,我可以返回两个文档:db.collection.find({'foo.data.text': {'$in': ['Y']}}
但是,我无法使用全文命令/索引返回这些结果:db.collection.runCommand("text", {search" "Y"})
我确信全文搜索正在运行,因为针对“Thing1”发出搜索的同一命令将返回第一个文档,而“Thing3”则返回第二个文档。
我确信使用时 foo.data.text 和 foo.name 都在文本索引中db.collection.getIndexes()
.
我使用以下方法创建了索引:db.collection.ensureIndex({'foo.name': 'text', 'foo.data.text': 'text'})
。以下是上述命令显示的索引:
{
"v" : 1,
"key" : {
"_fts" : "text",
"_ftsx" : 1
},
"ns" : "testing.collection",
"background" : true,
"name" : "my_text_search",
"weights" : {
"foo.data.text" : 1,
"foo.name" : 1,
},
"default_language" : "english",
"language_override" : "language",
"textIndexVersion" : 1
}
关于如何让它工作的任何建议mongo的全文搜索 http://docs.mongodb.org/manual/tutorial/search-for-text/?