2016-07-25 45 views
2

是否有可能$和運營商多個$文本索引搜索mongo?

我有我的分貝的TP集合

> db.tp.find() 
{ "_id" : ObjectId("...."), "name" : "tp", "dict" : { "item1" : "random", "item2" : "some" } } 
{ "_id" : ObjectId("...."), "name" : "tp", "dict" : { "item3" : "rom", "item4" : "tttt" } } 

然後在文件我做

> db.tp.createIndex({ "$**": "text" }) 
> db.tp.find({ $and: [{$text : { $search: "random" } }, {$text : { $search: "redruth" } }]}) 

而且與單一搜索

Error: error: { 
"waitedMS" : NumberLong(0), 
"ok" : 0, 
"errmsg" : "Too many text expressions", 
"code" : 2 
} 

但文本索引搜索工作這麼失敗是不是可以使用$和operator綁定多個文本搜索?順便說一下,我使用通配符$**進行索引,因爲我想搜索整個文檔。

回答

0

基礎上mongoDB文檔和操作員可以通過組合報價和空間搜索詞直接使用。例如,我們搜索「SSL證書」和「權限密鑰」,所以查詢應該是這樣的:

> db.tp.find({'$text': {'$search': '"ssl certificate" "authority key"'}})