Is there any way to search (FULLTEXT) in a specific field in Mongodb?

Asked

Viewed 348 times

2

I have a full-text index in Mongodb and I need to search only on top of one field instead of all. Does anyone know if this is possible?

2 answers

1

In accordance with the mongodb documentation, it supports indexing and text searching from version 2.4, if enabled. As of version 2.6, this feature is available by default.

To create a text index, do:

db.reviews.ensureIndex( { comments: "text" } )

Text indexing engine supports multiple languages, listed here.

To perform the search, use the operator $text, whose syntax is:

{ $text: { $search: <string>, $language: <string> } }

0

Browser other questions tagged

You are not signed in. Login or sign up in order to post.