Ruby Operation MongoDB (Advanced 10)--Text Search

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.