I'm trying to get mongodb fulltext search with multiple fields working.
I've set the index on 3 fields-name,description, category, and verified with
document.collection.getIndexes ()
,
which returns-
[
{
"v" : 1,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "document.collection"
},
{
"v" : 1,
"key" : {
"name" : 2,
"description" : 1,
"category" : 1
},
"name" : "name_2_description_1_category_1",
"ns" : "document.collection",
"background" : true,
"safe" : null
}
]
Now, if I try to perform a text search, using the follwing command-
db.collection.find( {$text:{$search:'alias'}} ).limit(10)
got the following error message:
error: {
"$err" : "Unable to execute query: error processing query: ns=document.collection limit=10 skip=0
Tree: TEXT : query=alias, language=, tag=NULL
Sort: {}
Proj: {}
planner returned error: need exactly one text index for $text query",
"code" : 17007
}
I tried google and mongodb docs but I couldn't find anything.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…