MongoDB Full-text Indexing Usage

Source: Internet
Author: User
Tags mongodb
How to create a Full-text index:
Db.ensureindex ({key: "text"})
Db.ensureindex ({key1: "text", Key2: "Text"})
Db.ensureindex ({"$**": "Text", Key2: "Text"})


MongoDB the use of Full-text indexing queries:
Db.article.find ({$text: {$search: "Coffee"}}) #查询包含coffee的内容的文档
Db.article.find ({$text: {$search: "AA bb cc"}}) # (or query) query for documents that contain contents of AA or BB or cc
Db.article.find ({$text: {$search: "AA Bb-cc"}}) #-to exclude documents containing CC content
Db.article.find ({$text: {$search: "\ aa\" \ "bb\" \ "Cc\"}) # (with query) add \ Before querying, and query for documents that contain both AA and BB cc content.


Limitations of Full-text Indexing:
A collection can only create one Full-text index, and only one $text query can be specified per query
$text cannot appear in the $nor query
$hint does not work if the query contains $text
Chinese Full-text search is not supported
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.