The MongoDB database provides a text index on the search query operation on top of the text content, and the text index can be applied to all fields of a string or character array. To use text search on a ruby driver, first create a text index using the Indexes.create_one () method. In the following instance, the result of the restaurants collection in the test database, a text index was created for the name field.
Client=mongo::client.new ([' 127.0.0.1:27017 '],:d atabase=> ' test ') Client[:restaurants].indexes.create_one ({: name=> ' Test '})
Once you have created a text index, you can use it as part of the query, and the following case finds all documents containing garden in the restaurants collection, and is not case sensitive.
Client=mongo::client.new ([' 127.0.0.1:27017],:d atabase=> ' test ') client[:restaurant].find ({' $test ' =>{' $search ' = ' garden ', ' $caseSenstive ' =>false}}). All do |document|end
This blog explains the text search in MongoDB. The method is to create a text index in the field fields where the value is text.
This article from "Techfuture" blog, declined reprint!
Ruby Operation MongoDB (Advanced 10)--Text Search