> Db.articles.createIndex ({subject:"text" } ){ "createdcollectionautomatically":true, "Numindexesbefore":1, "Numindexesafter":2, "OK":1}>Db.articles.insert (... [... {_id:1, Subject:"Coffee", Author:"XYZ", Views: - },... {_id:2, Subject:"Coffee Shopping", Author:"EFG", Views:5 },... {_id:3, Subject:"Baking a cake", Author:"ABC", Views: - },... {_id:4, Subject:"Baking", Author:"XYZ", Views: - },... {_id:5, Subject:"Caf Con Leche", Author:"ABC", Views: $ },... {_id:6, Subject:".......", Author:"JKL", Views: the },... {_id:7, Subject:"Coffee and Cream", Author:"EFG", Views:Ten },... {_id:8, Subject:"Cafe con Leche", Author:"XYZ", Views:Ten }... ] ... ) Bulkwriteresult ({"writeerrors" : [ ], "writeconcernerrors" : [ ], "ninserted":8, "nupserted":0, "nmatched":0, "nmodified":0, "nremoved":0, "upserted" : [ ]})> Db.articles.Find({$text: {$search:"Coffee" } } ){ "_id":2,"subject":"Coffee Shopping","author":"EFG"," views":5 }{ "_id":7,"subject":"Coffee and Cream","author":"EFG"," views":Ten }{ "_id":1,"subject":"Coffee","author":"XYZ"," views": - }> Db.articles.Find({$text: {$search:"\ "Coffee Shop\"" } } ){ "_id":2,"subject":"Coffee Shopping","author":"EFG"," views":5 }> Db.articles.Find({$text: {$search:"\ "Coffee\" \ "Shop\"" } } ){ "_id":2,"subject":"Coffee Shopping","author":"EFG"," views":5 }> Db.articles.Find({$text: {$search:"Coffee Shop" } } ){ "_id":2,"subject":"Coffee Shopping","author":"EFG"," views":5 }{ "_id":7,"subject":"Coffee and Cream","author":"EFG"," views":Ten }{ "_id":1,"subject":"Coffee","author":"XYZ"," views": - }
Reference: https://docs.mongodb.com/manual/reference/operator/query/text/
MongoDB Full Text Search--Search for a specific field is not yet supported