3

我们有一种情况,用户希望有一个“多功能框”来搜索文档中任何位置的单词\短语。

MongoDB 是否能够执行此搜索,还是必须对每个字段进行显式搜索?

4

1 回答 1

3

You need to create a wildcard text indexes like this:

db.collection.createIndex( { "$**": "text" } )

You can the use the $text operator to performs a text search.

As mentioned in the documentation:

This index allows for text search on all fields with string content. Such an index can be useful with highly unstructured data if it is unclear which fields to include in the text index or for ad-hoc querying.

于 2016-02-04T16:27:08.380 回答