我有我試圖文本索引文件是文件列表的問題:MongoDB的文本索引對象數組列
我先插入到DB:
db.userlikes.insert({
"data": [
{
"category": "Non-profit organization",
"name": "Animals"
},
{
"category": "Community",
"name": "Computers"
}
]
})
然後我想以創建類別列的索引:
db.userlikes.ensureIndex({"data.category": "text"})
但是,當我試圖尋找我沒有得到任何結果:
db.userlikes.find({"data.category": "profit"})
是不是可以索引這種方式?最好的方法是將每個文檔分別插入到數組中(「數據」)?這將是一個開銷,因爲我只想插入到從API獲取的數據庫響應中。
請幫幫我。
謝謝
,您好:感謝您的回覆,我也試過db.userlikes.find({$文字:{$搜索:「利潤」}}),但沒有運氣:(我仍然沒有結果 – EA9 2014-09-21 12:46:04
然後你我創建了一個包含示例數據的集合,通過db.userlikes.ensureIndex({「data.category」:「text」})添加了一個文本索引,併發送了查詢db.userlikes.find( {$ text:{$ search:「profit」}})',這給了我預期的結果。 – 2014-09-22 10:54:58