In my article collection, I have a text index:
{ "v" : 1, "key" : { "_fts" : "text", "_ftsx" : 1 }, "name" : "title_text_abstract_text_body_text", "ns" : "foo.articles", "weights" : { "abstract" : 1, "body" : 1, "title" : 1 }, "default_language" : "english", "language_override" : "language", "textIndexVersion" : 2 }
In my article collection, I have an entry like this:
{ "_id" : ObjectId("5477c28c807a9cd660ccd567"), "title" : "Hallo Welt!", "author" : "foo", "publishDate" : ISODate("2014-11-28T17:00:00Z"), "language" : "de", "abstract" : "Mein erster Artikel!", "body" : "Dieser Artikel ist in deutscher Sprache.", "__v" : 0 }
(In fact, there are different meanings in abstract and body , for brevity, let's look at them above)
When I try to find this article:
db.articles.find({$text: {$search: 'Welt'}})
He is found.
But: When I try to find this article:
db.articles.find({$text: {$search: 'Sprache'}})
I am not getting any results. But after I changed language to en or none , I get this article as a result with the same query.
What am I doing wrong?
Edit : As requested in the comments, here are the exact commands that lead to the behavior described above. It was supposed to do it this way, first of all, an apology.
> db.test.drop() true > db.test.insert({language: "de", body: "vermutlich", title: "Artikel"}) WriteResult({ "nInserted" : 1 }) > db.test.ensureIndex({body: "text", title: "text"}) { "createdCollectionAutomatically" : false, "numIndexesBefore" : 1, "numIndexesAfter" : 2, "ok" : 1 } > db.test.find({$text: {$search: 'vermutlich'}}) > db.test.find({$text: {$search: 'Artikel'}}) { "_id" : ObjectId("54ea86d6c9ec98269e022c67"), "language" : "de", "body" : "vermutlich", "title" : "Artikel" } > db.version() 2.6.5
I also tried changing the language again:
> db.test.update({}, {$set: {language: "en"}}) WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 }) > db.test.find({$text: {$search: 'Artikel'}}) { "_id" : ObjectId("54ea86d6c9ec98269e022c67"), "language" : "en", "body" : "vermutlich", "title" : "Artikel" } > db.test.find({$text: {$search: 'vermutlich'}}) { "_id" : ObjectId("54ea86d6c9ec98269e022c67"), "language" : "en", "body" : "vermutlich", "title" : "Artikel" }
Edit: Okay, so I just tried rebuilding this example. But I also added one German quote, so this is what I did:
> db.test.drop() true > db.test.insert({ language: "portuguese", original: "A sorte protege os audazes.", translation: [{ language: "english", quote: "Fortune favors the bold."},{ language: "spanish", quote: "La suerte rotege a los audaces."}]}) WriteResult({ "nInserted" : 1 }) > db.test.insert({ language: "spanish", original: "Nada hay más surrealista que la realidad.", translation:[{language: "english",quote: "There is nothing more surreal than reality."},{language: "french",quote: "Il n'y a rien de plus surrĂ©aliste que la rĂ©alitĂ©."}]}) WriteResult({ "nInserted" : 1 }) > db.test.insert({ original: "is thisdagger which I see before me.", translation: {language: "spanish",quote: "Es este un puñal que veo delante de mĂ." }}) WriteResult({ "nInserted" : 1 }) > db.test.insert({original: "Die Geister, die ich rief...", language: "german", translation: {language: "english", quote: "The spirits that I've cited..."}}) WriteResult({ "nInserted" : 1 }) > db.test.ensureIndex( { original: "text", "translation.quote": "text" } ) { "createdCollectionAutomatically" : false, "numIndexesBefore" : 1, "numIndexesAfter" : 2, "ok" : 1 }
Then I tried a few queries:
> db.test.count({$text: {$search: "delante"}}) 1 > db.test.count({$text: {$search: "spirits"}}) 1 > db.test.count({$text: {$search: "Geister"}}) 0
Conclusion: mongoDB does not work with German? It is really frustrating