mongodbHow to do text search in MongoDB?
Text search in MongoDB can be done using the $text
operator. This operator allows for a full-text search of string content in a collection.
Example code
db.collection.find({$text: {$search: "text to search"}})
Output example
{ "_id" : ObjectId("5f3d7f9f8f9f9f9f9f9f9f9f"), "name" : "John Doe", "text" : "This is some text to search" }
Code explanation
db.collection.find()
: This is the MongoDB command to query a collection.$text
: This is the MongoDB operator used to perform a full-text search.$search
: This is the parameter used to specify the text to search for.
Helpful links
More of Mongodb
- What is MongoDB default port?
- How to use watch in MongoDB?
- How to list MongoDB users?
- How to use MongoDB queue?
- How to use MongoDB push?
- How to implement one-to-many relation in MongoDB?
- How to convert MongoDB ObjectId to string?
- How to query with "not in" condition in MongoDB?
- How to query with "not equal" condition in MongoDB?
- How to use triggers in MongoDB?
See more codes...