To test your full-text search query, you can use the MongoDB Atlas Data Explorer or any MongoDB client that supports Atlas Search. You can run your query and inspect the results, which will include a score for each document and a highlight field for each matching field. The score indicates how relevant the document is to the query, and the highlight field shows the matching snippets with HTML tags. For example, here is a sample result for the previous query:
{
"_id": ObjectId("60b6c5f4a8d2f9f3a9f8b1e2"),
"title": "How to <em>database</em> with MongoDB",
"content": "MongoDB is a NoSQL <em>database</em> that offers flexibility, scalability, and performance.",
"score": 2.0,
"highlight": {
"title": "How to <em>database</em> with MongoDB",
"content": "MongoDB is a NoSQL <em>database</em> that offers flexibility, scalability, and performance."
}
}
You can use the score and the highlight fields to rank and display the results to your users.
Full-text search is a useful feature that can enhance your MongoDB application and provide a better user experience. By following these three steps, you can add full-text search to your MongoDB application and leverage the power of Atlas Search.