node.js - search in a mongod database -


Im trying to search in a database, but I do not get any results, and can not find the error Get an empty array in the I console, but the database is full of elements included in this element "a".

If I try to find everyone in the database then I get all the results, $ search or $ text which breaks the script.

All help is really appreciated, I have been sitting and tearing my hair for a few days!

  Use the app (bodyParser.json ()); App.use (bodyParser.urlencoded ({extended: true})); Var DB; MongoClient.connect ("mongodb: // localhost: 27017 / insight"), function (fault, database) {db = database; db.collection ("textstore", {}, function (mistake, coll) {if (err! = Null) {db.createCollection ("textstore", function (error, result) {assert.equal (null, err);})}} db.ensureIndex ("textstore", {document: "text"}, function, index Name) {assert.equal (zero, mistake);});});}); App.post ("/ search", function (rick, race) {db.collection ('textstore'). ({"$ Text": {"$ search": 'a'}}. ToArray (function fault, Items) {console.log (items)})}); A MongoDB is the search language, and the default language is English.  
a is such a word:

MongodiBi supports text search for different languages. Text indexes drop language-specific stop words. (Such as in English, "the", "a", "a", "and", etc.) and uses ordinary language-specific suffixes.

Try to disable either by looking for something more meaningful or by clearly setting language in "none" while searching language awareness.

  db.collection ('textstore') .find ({"$ text": {"$ search": 'a', $ language: "none"}})  

By the way, you can also override the default language when you create an index and even override it at the document and sub-document level. for more information,.


Comments