Explore Developer Center's New Chatbot! MongoDB AI Chatbot can be accessed at the top of your navigation to answer all your MongoDB questions.

Learn why MongoDB was selected as a leader in the 2024 Gartner® Magic Quadrant™
MongoDB Developer
Atlas
plus
Sign in to follow topics
MongoDB Developer Center
chevron-right
Developer Topics
chevron-right
Products
chevron-right
Atlas
chevron-right

Getting Started with MongoDB Atlas Local Search Experience Using Docker

Michael Höller6 min read • Published Jan 15, 2025 • Updated Jan 16, 2025
SearchAtlas
Facebook Icontwitter iconlinkedin icon
Rate this tutorial
star-empty
star-empty
star-empty
star-empty
star-empty
This tutorial will walk you through setting up MongoDB Atlas Local Search with Docker, populating a local database with sample data, and configuring a search index. This is ideal for developers looking to streamline their search-driven application workflows, test full-text or AI-powered search locally, and improve their productivity by working with rapid, low-latency feedback loops directly in their preferred environment.
Before diving into Docker-based local setups, it's worth noting that the MongoDB Atlas CLI offers a streamlined approach to managing MongoDB Atlas deployments. This command-line tool simplifies tasks such as creating clusters, managing indexes, and configuring databases, allowing developers to handle these operations efficiently from the terminal.
The Atlas CLI also enables the creation and management of local environments, which are delivered using Docker. For those who prefer hands-on control over local environments, this tutorial leverages Docker directly to demonstrate the flexibility and power of MongoDB Atlas Local Search, enabling rapid prototyping and local experimentation.

Why MongoDB Atlas Local Search?

Modern application development increasingly demands advanced search-driven features that combine flexible indexing, high performance, and rapid iteration. MongoDB Atlas Local Search is designed to meet these needs by providing developers with robust tools that emphasize developer ergonomics and fast feedback loops, essential for efficient and effective application prototyping.

Developer Ergonomics

MongoDB Atlas Local Search streamlines the development process by enabling seamless integration with your preferred local environment. This eliminates the friction often encountered when switching between local development and remote systems. Developers can configure, query, and test search features directly within their familiar tools, benefiting from MongoDB’s flexible schema model and powerful query capabilities. Moreover, the local setup allows for immediate adjustments to index configurations and search parameters, reducing the overhead associated with remote deployment and iteration. With Docker-based setups, the environment is easily reproducible, ensuring consistent development experiences across teams and projects.

Fast Feedback Loops

Speed is critical during the development and testing phases, and MongoDB Atlas Local Search delivers unparalleled efficiency in this regard. Local clusters are exceptionally fast to deploy and dismantle, allowing developers to quickly spin up instances for testing new features or debugging. The absence of network latency ensures near-instantaneous read and write operations, enabling developers to test changes in real-time. Whether experimenting with full-text search queries, vector-based search for AI-driven applications, or refining index configurations, the rapid feedback cycle accelerates development workflows and minimizes downtime. This agility fosters an iterative process where developers can make incremental improvements with confidence, significantly enhancing overall productivity.
By combining these advantages, MongoDB Atlas Local Search provides a powerful solution for building modern search-driven applications and empowers to focus on innovation and functionality without being hindered by the complexities of remote infrastructure or slow feedback cycles.

Prerequisites

Before starting, ensure you have the following:
The repository includes Docker configurations, sample data, and example code to simplify getting started with MongoDB Atlas Local Search.

Create a Local Atlas Deployment with Docker

Follow these step-by-step instructions to get started:
Step #1: Pull the MongoDB Atlas Local Docker Image
Run the following command to download the latest MongoDB Atlas Local Docker image:
1docker pull mongodb/mongodb-atlas-local:latest
If you run docker pull mongodb/mongodb-atlas-local without specifying a version tag, Docker automatically retrieves the latest version of the image (mongodb/mongodb-atlas-local:latest).
To pull a specific version of the Docker image, use this command, replacing <tag> with the desired version tag:
1docker pull mongodb/mongodb-atlas-local:<tag>
Step #2: Run the Database
Start the MongoDB container:
1docker run -p 27017:27017 mongodb/mongodb-atlas-local
Step #3: Connect to the Database
Open a second terminal (since the MongoDB container is running in foreground mode) and connect using mongosh. For this basic example, authentication is not enabled:
1mongosh "mongodb://localhost/?directConnection=true"
Atlas Local Search
Congratulations! You now have a fully functional local Atlas deployment with search capabilities.

Create and Test a Search Index

To verify the setup, let’s create a search index and test it.
Step #1: Insert Sample Data
Use the following commands to insert some sample data into a collection:
1use test
2db.sampleAtlasSearch.insertMany([
3 { item: "card", qty: 15 },
4 { item: "envelope", qty: 20 },
5 { item: "stamps", qty: 30 }
6]);
Step #2: Create a Search Index
Create a simple dynamic search index:
1db.sampleAtlasSearch.createSearchIndex({ mappings: { dynamic: true } });
Step #3: Verify the Index
Check that the search index was created successfully:
1db.sampleAtlasSearch.getSearchIndexes();
Voilà! Your first search index in a local Atlas deployment:
Atlas Local Search

What’s Next?

Now that you’ve covered the basics, let’s explore how MongoDB Atlas Local Search can add value to your day-to-day work.
Next, we will:
  • Set up a Local Atlas Deployment with Docker Compose
  • Learn how to seed data
  • Create and run search indexes
  • Use MongoDB Compass to connect to the deployment

Create a Local Atlas Deployment with Docker

To make this tutorial convenient to follow and help you get started with MongoDB Atlas Local Search, I have prepared a repository containing everything you need, including Docker configuration, sample data, and example code. To follow along, please clone the MongoDB Local Atlas repository.

What's in the Box?

Let’s take a look at the docker-compose.yml file to understand how the environment is configured:
1services:
2 mongodb:
3 image: mongodb/mongodb-atlas-local
4 environment:
5 - MONGODB_INITDB_ROOT_USERNAME=user
6 - MONGODB_INITDB_ROOT_PASSWORD=pass
7 - RUNNER_LOG_FILE=/dev/stderr
8 ports:
9 - 27018:27017
10 volumes:
11 - ./init:/docker-entrypoint-initdb.d
12 - ${PWD}/upload/restaurants.json:/tmp/restaurants.json

Key Configuration Details:

  1. Service Definition
    The mongodb service uses the mongodb/mongodb-atlas-local image, which includes MongoDB server, Atlas Search, and Vector Search. You can specify a MongoDB version by appending a version tag to the image name, e.g., mongodb/mongodb-atlas-local:8.0. For available versions, refer to the MongoDB repository on Docker Hub.
  2. Environment Variables
    • MONGODB_INITDB_ROOT_USERNAME and MONGODB_INITDB_ROOT_PASSWORD define the default credentials for the root user.
    • RUNNER_LOG_FILE is optional but useful for logging errors during initialization to the console.
  3. Port Mapping
    The database is exposed to the local host on port 27018.
  4. Volumes for Seeding
    • Initialization scripts for seeding the database are loaded from the ./init directory, mounted as /docker-entrypoint-initdb.d inside the container.
    • The sample data file restaurants.json is mounted to /tmp/restaurants.json inside the container.
  5. Health Check
    A health check is not required, as it is built into the mongodb-atlas-local image.

Spin Up the Deployment

To start the deployment, run the following command:
1docker compose up

What Happens:

  1. The local environment is created, including the core database and Atlas Search functionality.
  2. Initialization scripts for database seeding are executed in alphanumeric order from the ./init directory.
You should see that the local-atlas-mongodb container has started:
Deployment Up
To verify, run:
1docker container list
This will display a list of running containers and their statuses:
Container List

Database Seeding

As mentioned earlier, initialization scripts are loaded from the ./init directory and executed in alphanumeric order inside the container's /docker-entrypoint-initdb.d.
Here’s how the seeding process works in this example:
Step #1: 00-import-from-export.sh
This script uses mongoimport to load data exported from another MongoDB database/collection. This is ideal for replicating a reference installation for development or testing. The file must be accessible in the container through the mounted volume. Alternatively, you can download the file directly into the container using curl and then import it:
1curl -o /tmp/mydatafile.json https://data.somewhere/mydatafile.json
2mongoimport --uri $CONNECTION_STRING --collection=restaurants --db=myplaces --file=/tmp/mydatafile.json
Step #2: 01-import-explicit-inserts.js
This script seeds data by executing insertMany commands in the MongoDB shell. For example:
1db.getSiblingDB('myplaces').getCollection('restaurantsExtra').insertMany([
2 { /* data */ },
3 { /* data */ }
4]);
Step #3: 02-create-search-index.js
This script creates a search index on the name field of the restaurants collection. Example:
1{
2 "mappings": {
3 "dynamic": false,
4 "fields": {
5 "name": {
6 "type": "string",
7 "analyzer": "lucene.standard"
8 }
9 }
10 }
11}

Connect to the Database

With the database running, you can connect to it using various tools:
MongoDB Shell
Connect using the following command:
1mongosh "mongodb://user:pass@localhost:27018/?directConnection=true"
Atlas Local Search
MongoDB Compass
Add the connection string in Compass to connect:
MongoDB Compass

Verify the Seeding

Data Verification
  • 00-import-from-export.sh should populate the myplaces.restaurants collection.
  • 01-import-explicit-inserts.js should add data to myplaces.restaurantsExtra.
Both collections should be visible in Compass:
MongoDB Compass
Search Index
02-create-search-index.js should create a search index on the name field of the restaurants collection. You can verify the index in Compass:
MongoDB Compass
MongoDB Compass

Run an Atlas Search Query

Now, let’s run an Atlas Search query using MongoDB Compass. This query performs a fuzzy search on the name field of the restaurants collection and limits the results to the top three.
1[
2 {
3 "$search": {
4 "index": "default",
5 "text": {
6 "query": "Food",
7 "path": "name",
8 "fuzzy": { "maxEdits": 2 }
9 }
10 }
11 },
12 { "$limit": 3 },
13 {
14 "$project": {
15 "_id": 0,
16 "name": 1,
17 "cuisine": 1
18 }
19 }
20]
MongoDB Compass

Convert an Existing Deployment

If you have an existing Atlas implementation using the official mongo Docker image, refer to this guide for a checklist to transition to the mongodb-atlas-local image.

Conclusion

This tutorial has provided a comprehensive introduction to setting up and leveraging MongoDB Atlas Local Search within a Dockerized environment. By following the steps outlined, you have configured a local deployment, inserted sample data, created dynamic search indexes, and tested the setup through Atlas Search queries. These processes empower you to iterate rapidly, optimize workflows, and build robust search-driven applications with minimal overhead.
The integration of MongoDB Atlas Local Search with Docker enhances developer productivity by enabling a seamless local testing environment that mirrors production-like capabilities. This streamlined approach eliminates the latency and complexity often associated with remote environments, allowing for precise configuration and real-time experimentation. The Docker Compose configurations and initialization scripts further simplify team collaboration, ensuring consistent environments across diverse systems.
As you continue to explore MongoDB Atlas Local Search, consider how its capabilities—like full-text search, AI-driven vector searches, and dynamic indexing—can enhance your application’s functionality and user experience. By incorporating advanced search features locally, you can focus on refining your application’s core logic, optimizing search performance, and delivering value faster.
Top Comments in Forums
There are no comments on this article yet.
Start the Conversation

Facebook Icontwitter iconlinkedin icon
Rate this tutorial
star-empty
star-empty
star-empty
star-empty
star-empty
Related
Tutorial

MongoDB Atlas With Terraform - Cluster and Backup Policies


Sep 11, 2024 | 22 min read
Tutorial

Tutorial: Build a Movie Search Engine Using Atlas Full-Text Search in 10 Minutes


Sep 09, 2024 | 10 min read
Tutorial

Building a Knowledge Base and Visualization Graphs for RAG With MongoDB


Sep 02, 2024 | 12 min read
Code Example

Blogue


Sep 11, 2024 | 1 min read
Table of Contents