Member-only story
Learn Advanced Full-Text Searches With MongoDB Atlas Search
Let’s search with MongoDB rather than Elasticsearch
As we have learned in a previous post, we can run full-text search queries with MongoDB Atlas Search now. If you are implementing a search engine and haven’t decided which tool to use, MongoDB Atlas Search can be a good alternative to traditional tools like Elasticsearch. In this post, we will introduce some advanced settings and search queries for MongoDB Atlas Search. You will find that they are pretty similar to their counterparts in Elasticsearch. This is because, under the hood, Apache Lucene is used as the core for both Elasticsearch and MongoDB.
It should be noted that MongoDB Atlas Search is only available if your MongoDB databases are hosted by MongoDB Atlas. It’s not available if you manage your MongoDB servers locally.
We will continue to use the laptops
collection in the products
database we’ve been working on because the product names and attributes are good examples for demonstrating full-text searches.
And if you want to follow along, please download the JSON file and use the following command to import the data to MongoDB Atlas.
Note that you need to change the username, password, and cluster name for your own case. If you have network connection issues, remember to check if your IP address is added to the IP Access List in Atlas UI.
When the above command is run, you will have the products
database and laptops
collection created automatically in MongoDB Atlas, which contains 200 laptop documents as follows:
Let’s now create an Atlas Search Index that will be used for full-text searches. You can create an Atlas Search Index with the Atlas UI, Atlas…