mongodb - Meteor Text Search has no results? -


my webapp consists of list of topics , search field filter them with.

i started inserting object mongodb:

$meteor mongo meteor:primary> db.topics.insert({title:"hello world!"}); 

i wrote in .coffee file verify showed expected:

topics = new mongo.collection "topics"  if meteor.isclient     template.body.helpers {         topics: -> topics.find {}     } 

that worked fine. decided move having fixed filter of "hello". replaced topics.find {} with:

topics.find {$text: {$search: "hello"}} 

this caused list appear empty. tried this:

topics.find {title: {$text: {$search: "hello"}}} 

but did not work. missing here?

(also, first time using coffeescript. generated javascript file looked right me, if see unnecessary punctuation or other bad habits in here, please point out me. tends python programmers, know how obnoxious people new language littering unnecessary semicolons.)

update

i have added in following server code directed blakes 7 in answer:

if meteor.isserver     meteor.startup -> topics._ensureindex {title: "text"} 

if query mongodb command line below, works fine:

$meteor mongo meteor:primary> db.topics.find({$text: {$search: "hello"}}) { "_id" : objectid("559495cf7b8f68a693d8a3a8"), "title" : "hello world!" } 

however, within application, in client code, topics.find {$text: {$search: "hello"}} still not working.

update 2

blakes 7 wanted see this:

$meteor mongo meteor:primary> db.topics.getindexes() [     {         "v" : 1,         "key" : {             "_id" : 1         },         "name" : "_id_",         "ns" : "meteor.topics"     },     {         "v" : 1,         "key" : {             "_fts" : "text",             "_ftsx" : 1         },         "name" : "title_text",         "ns" : "meteor.topics",         "safe" : true,         "weights" : {             "title" : 1         },         "default_language" : "english",         "language_override" : "language",         "textindexversion" : 2     } ] 

you need create "text index" on collection before can perform $text search queries.

you can create index deploy in meteor.startup under server/indexes as:

meteor.startup(function() {      topics._ensureindex({ "title": "text" })  ]); 

mongodb 3.x series recommends it's method .createindex(), current meteor methods still calling .ensureindex() @ present.

this isn't of concern preferred method has expanded sytax support additional features mostly, , none of these should general concern.

if find need features, can script "index" deployment outside of meteor application code.


just sidenote, it's general convention refer collection model both in "singular" rather "plural" form, collection "plural" , not model. general convention "capital" first.


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -