Docs Menu

Text Search Operators (Self-Managed Deployments)

注意

このページでは、自己管理型(Atlas以外)デプロイメントのテキスト クエリ機能について説明します。 MongoDB Atlasでホストされているデータに対して、 MongoDB は改良された全文クエリ ソリューションである Atlas Search とベクトル検索ソリューションである Atlas ベクトル検索 を提供します。

Use the $text query operator to perform text searches on a collection with a text index.

$text tokenizes the search string using whitespace and most punctuation as delimiters, and perform a logical OR of all such tokens in the search string.

For example, you could use the following query to find all stores containing any terms from the list "coffee", "shop", and "java" in the stores コレクション:

db.stores.find( { $text: { $search: "java coffee shop" } } )

Use the $meta query operator to obtain and sort by the relevance score of each matching document. For example, to order a list of coffee shops in order of relevance, run the following:

db.stores.find(
{ $text: { $search: "coffee shop cake" } },
{ score: { $meta: "textScore" } }
).sort( { score: { $meta: "textScore" } } )

For more information on the $text and $meta operators, including restrictions and behavior, see:

When working with 集計 pipelines, use $match with a $text expression to execute a text search query. To sort the results in order of relevance score, use the $meta aggregation operator in the $sort stage [1].

For more information and examples of $text in 集計操作 pipelines, see 自己管理型配置の集計パイプラインの $text.

MongoDB Atlas でホストされているデータの場合、Atlas Search はコレクションの全文検索を実行するための $search 集計ステージを備えています。

[1] The behavior and requirements of the $meta projection operator differ from that of the $meta aggregation operator. For details on the $meta aggregation operator, see the $meta aggregation operator reference page.