Like query in MongoDB

Source: Internet
Author: User

If the string to be searched is "S", you can use the following four methods:

  1. DB. Tables. Find ({"Name":/S /})
  2. DB. Tables. Find ({"Name":/^ s /})
  3. DB. Tables. Find ({"Name":/S .*/})
  4. DB. Tables. Find ({"Name":/. S .*/})

The following analyzes the differences between the results of these queries:

1) dB. City. Find ({"Region":/. New .*/})

A total of 765 records: including [new and high technologies. Hi-Tech Zone, huqiu. Yubei district (including northern New District )]
[Note: The result shows the queried data.Must be preceded by characters, Which is equivalent to DB. city. find ({"region ":/. new. /}), which is also equivalent to DB. city. find ({"region ":/. new /})]

-----------------------------------------------------------------------------

2) dB. City. Find ({"Region":/^ new /})

A total of 592 records: including [Xinhua. Xinzhou. Xindu. New City. New Area]
[Note: The result shows that the queryIt must start with the characters to be queried.]

-----------------------------------------------------------------------------

3) dB. City. Find ({"Region":/New .*/})

A total of 1357 records: The records contain [Xinhua. High technology. Yubei district (including the northern New Area ). High-tech zone, huqiu]
[Note: The result shows thatThe preceding characters may or may not exist., Equivalent to: DB. City. Find ({"region":/New /})]

-----------------------------------------------------------------------------

Finally, we analyze the record results. From the above three queries, we can see that the results of the first two queries are exactly the same as those of the last query, which is fully consistent with the annotations.

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.