MongoDB Shell, Compass, and Stitch
MongoDB Shell, Compass, and Stitch Interview with follow-up questions
1. What is MongoDB Shell and what are its uses?
MongoDB Shell — mongosh — is the official command-line interface for interacting with MongoDB. It's a Node.js-based, JavaScript REPL (the legacy mongo shell was removed in 6.0), so you write JS expressions and use the full driver-style API plus modern features like syntax highlighting, autocompletion, and loadable scripts. Common uses:
- Querying and retrieving data from collections
- Inserting, updating, and deleting documents (CRUD)
- Creating and managing indexes
- Administrative tasks: managing users, roles, databases, and replica-set/shard config
- Running JavaScript and
.jsscript files for automation - Monitoring and analyzing performance (
explain(),db.serverStatus(),db.currentOp()) - Importing/exporting and ad-hoc data fixes
It connects to local deployments or Atlas via a connection string (mongosh "mongodb+srv://..."). For day-to-day work it's complemented by Compass (GUI) and the VS Code MongoDB extension, but mongosh remains the go-to for scripting and admin.
Follow-up 1
Can you explain how to connect to a MongoDB database using the MongoDB Shell?
To connect to a MongoDB database using the MongoDB Shell, follow these steps:
- Open a command prompt or terminal window.
- Type
mongoto start the MongoDB Shell. - By default, the MongoDB Shell connects to the local MongoDB server running on the default port
27017. If you want to connect to a different server or specify a different port, you can use the--hostand--portoptions followed by the server address and port number. - If authentication is enabled on the MongoDB server, you will need to provide the username and password using the
--usernameand--passwordoptions. - Once connected, you can start executing commands and interacting with the MongoDB database.
Follow-up 2
What are some common commands you can execute in the MongoDB Shell?
In MongoDB Shell, you can execute various commands to perform operations on the MongoDB database. Some of the common commands include:
use: Switches to the specified database.show collections: Lists all the collections in the current database.db..find(): Retrieves all documents from the specified collection.db..insertOne(): Inserts a new document into the specified collection.db..updateOne(, ): Updates a single document in the specified collection.db..deleteOne(): Deletes a single document from the specified collection.db..createIndex(, ): Creates an index on the specified collection.db..aggregate(): Performs aggregation operations on the specified collection.
These are just a few examples, and there are many more commands available in the MongoDB Shell.
Follow-up 3
How does MongoDB Shell differ from other database command line interfaces you have used?
MongoDB Shell differs from other database command line interfaces in several ways:
- MongoDB Shell uses JavaScript as its scripting language, which makes it easy to write and execute complex queries and operations.
- MongoDB Shell provides a rich set of built-in commands and functions specifically designed for working with MongoDB databases.
- MongoDB Shell has a flexible and interactive shell environment that allows for easy exploration and manipulation of data.
- MongoDB Shell supports various features such as autocompletion, syntax highlighting, and history navigation, which enhance the user experience.
- MongoDB Shell is tightly integrated with MongoDB, providing direct access to the database server and its components.
Overall, MongoDB Shell offers a powerful and user-friendly interface for interacting with MongoDB databases.
2. Can you explain what MongoDB Compass is and how it is used?
MongoDB Compass is the official GUI for MongoDB. It lets you connect to a deployment (local or Atlas, via a connection string) and explore and work with your data visually, without hand-writing every query. With Compass you can:
- Browse, filter, insert, edit, and delete documents (CRUD)
- Build queries and aggregation pipelines stage-by-stage with the visual builder, then export the code to your language of choice
- Analyze schema — see field types, value distributions, and frequencies across a collection
- Create, view, and manage indexes, and check index usage
- Run
explain()to inspect query plans and spot slow or unindexed queries - View real-time performance metrics
A 2026 interviewer expects you to position it as the developer/analyst tool for visual exploration, pipeline-building, and schema/index tuning — complementing mongosh (scripting/admin) and the VS Code MongoDB extension (in-editor work). It embeds the same mongosh engine in an integrated shell pane.
Follow-up 1
What are some of the key features of MongoDB Compass?
Some key features of MongoDB Compass include:
Schema Visualization: Compass provides a visual representation of the data schema, making it easier to understand the structure of the data.
Query Builder: Compass allows users to build queries using a visual interface, eliminating the need to write complex queries manually.
Real-time Data Exploration: Users can explore their data in real-time, with automatic updates as new data is added or modified.
Index Management: Compass allows users to create, modify, and delete indexes to optimize query performance.
Data Validation: Compass provides a validation feature that allows users to define rules for data integrity and enforce them at the database level.
User and Role Management: Users can manage database users and roles directly from Compass, making it easy to control access to the data.
Follow-up 2
How does MongoDB Compass assist in managing and navigating your data?
MongoDB Compass assists in managing and navigating data by providing a user-friendly interface for performing various tasks:
Data Exploration: Compass allows users to view and analyze their data in a visual and intuitive way. Users can navigate through collections, view documents, and filter data based on specific criteria.
Query Building: Compass offers a query builder tool that allows users to construct queries using a visual interface. This eliminates the need to write complex queries manually and makes it easier to retrieve the desired data.
Index Management: Compass provides a dedicated interface for managing indexes. Users can create, modify, and delete indexes to optimize query performance.
Data Validation: Compass allows users to define validation rules for their data and enforce them at the database level. This helps ensure data integrity and consistency.
User and Role Management: Compass allows users to manage database users and roles, controlling access to the data and ensuring proper security measures are in place.
Follow-up 3
Can you describe a scenario where you used MongoDB Compass to solve a problem?
Sure! One scenario where I used MongoDB Compass was when I needed to analyze and optimize the performance of a specific query in my application. Using Compass, I was able to visually explore the data and identify the fields that were frequently accessed in the query. I then created an index on those fields to improve the query performance. Compass also allowed me to test the query with different parameters and analyze the execution plan to further optimize its performance. Overall, Compass helped me gain insights into the data and make informed decisions to improve the application's performance.
3. What is MongoDB Stitch and how does it benefit developers?
Important correction: "MongoDB Stitch" no longer exists as a product name. Stitch was MongoDB's serverless backend platform (launched 2017); it was renamed MongoDB Realm in 2020 and then folded into Atlas App Services. So in 2026 you'd answer this by explaining what it became.
Conceptually, Stitch / Atlas App Services let developers build application backends without managing servers, offering: serverless Functions, Triggers (database/scheduled/auth events), built-in authentication, and data access rules to talk to Atlas directly from clients. The benefits pitch was less backend boilerplate, automatic scaling, and tight MongoDB integration.
The honest 2026 caveat an interviewer wants: this stack has been significantly wound down. MongoDB deprecated Atlas Device Sync and the Realm/Device SDKs (mobile support ended Sept 30, 2025), and the Atlas Data API and custom HTTPS endpoints reached end-of-life (~Sept 2025). So don't present Stitch as a thriving product — point to the current equivalents: Atlas Functions/Triggers, the standard MongoDB drivers for data access, and Atlas Search / Vector Search for app features.
Follow-up 1
Can you describe the main components of MongoDB Stitch?
The main components of MongoDB Stitch are:
Stitch App: It represents the entire application and contains all the configuration settings and services.
Services: These are the building blocks of a Stitch app and provide functionality such as authentication, database access, file storage, and more.
Rules: Rules define the access control and validation logic for the services. They determine who can access the services and what operations they can perform.
Triggers: Triggers are event-driven functions that can be executed in response to certain events, such as database changes or HTTP requests.
Functions: Functions are serverless JavaScript functions that can be used to implement custom backend logic.
Follow-up 2
How does MongoDB Stitch handle backend logic?
MongoDB Stitch allows developers to implement custom backend logic using serverless functions. These functions are written in JavaScript and can be executed in response to various events, such as HTTP requests, database changes, or scheduled intervals. Developers can write functions to perform complex operations, interact with databases, call external APIs, and more. MongoDB Stitch takes care of scaling and managing the execution of these functions, allowing developers to focus on writing the business logic of their applications.
Follow-up 3
Can you give an example of how you would use MongoDB Stitch in a project?
Sure! Let's say you are building a real-time chat application. With MongoDB Stitch, you can use the Stitch SDK to authenticate users, store chat messages in a MongoDB database, and implement real-time updates using MongoDB Change Streams. You can also use Stitch Functions to implement features like message filtering, user notifications, and message moderation. MongoDB Stitch simplifies the backend development by providing pre-built services and tools, allowing you to focus on building the frontend of your application.
4. How do MongoDB Shell, Compass, and Stitch work together in a MongoDB environment?
Quick correction on the premise: "Stitch" is a dead brand name. It became MongoDB Realm (2020) and then Atlas App Services, and that serverless stack is now largely deprecated (see below). The other two tools are current. Here's how the pieces fit in a 2026 MongoDB workflow:
MongoDB Shell (
mongosh) — the JavaScript command-line interface for CRUD, queries, indexing, scripting, and administration. The go-to for automation and admin tasks.MongoDB Compass — the GUI for visual data exploration, schema analysis, building aggregation pipelines, managing indexes, and inspecting query plans (
explain()). Best for interactive exploration and tuning."Stitch" / Atlas App Services — the former serverless backend (Functions, Triggers, auth, data access rules). It's been wound down: Device Sync and the Realm SDKs ended Sept 30, 2025, and the Data API / custom HTTPS endpoints reached EOL around the same time.
In practice today you connect both mongosh and Compass to the same cluster (local or Atlas) and use them side by side — shell for scripting, Compass for visual work. For serverless logic you'd use Atlas Functions/Triggers; for data access from apps, the standard drivers.
Follow-up 1
Can you give an example of a task that would require the use of all three - MongoDB Shell, Compass, and Stitch?
One example of a task that would require the use of all three tools is building a web application that needs to interact with a MongoDB database. MongoDB Shell can be used to write and test the JavaScript code for performing CRUD operations and running queries. Compass can be used to visually design the database schema, create and modify collections, and run queries. Stitch can be used to handle authentication, data synchronization between the client and server, and serverless functions for implementing business logic.
Follow-up 2
How do these tools improve the efficiency of working with MongoDB?
These tools improve the efficiency of working with MongoDB in several ways. MongoDB Shell provides a powerful command-line interface that allows users to quickly write and execute JavaScript code for interacting with the database. It provides a flexible and efficient way to perform CRUD operations, run queries, and manage the database. Compass provides a visual interface that makes it easier to explore the data, design the database schema, and run queries. It eliminates the need to write complex queries manually and provides a more intuitive way to interact with the database. Stitch simplifies the process of building and deploying applications that integrate with MongoDB. It provides pre-built features like authentication, data synchronization, and serverless functions, which saves developers time and effort.
Follow-up 3
What are some limitations of these tools?
While MongoDB Shell, Compass, and Stitch are powerful tools, they do have some limitations. MongoDB Shell requires knowledge of JavaScript and the MongoDB query language, which may be a barrier for users who are not familiar with these technologies. Compass has a graphical interface, but it may not be as efficient as using the command-line interface for certain tasks. It also requires a desktop installation, which may not be suitable for all environments. Stitch is a serverless platform, which means it has some limitations in terms of scalability and customization compared to a traditional server-based architecture. Additionally, using Stitch may introduce additional complexity and dependencies in the application architecture.
5. Can you describe a scenario where you would prefer to use MongoDB Shell over Compass, or vice versa?
The two tools serve different workflows, and a good answer gives concrete scenarios for each.
Prefer mongosh (the shell) when you need control, repeatability, and automation:
- Scripting bulk or scheduled operations (a
.jsfile that migrates data, backfills a field, or rotates users) - Administrative work — creating users/roles, configuring a replica set or sharding, running
db.currentOp()/db.killOp() - Anything you want to version-control, run in CI, or execute over SSH on a headless server where no GUI is available
- Complex, parameterized aggregations driven by loops or variables
Prefer Compass (the GUI) when visual exploration speeds you up:
- Exploring an unfamiliar dataset or analyzing schema (field types, value distributions)
- Building and iterating on an aggregation pipeline stage-by-stage, then exporting the code
- Eyeballing documents, doing quick ad-hoc edits, and managing/inspecting indexes
- Reviewing
explain()plans visually to diagnose a slow query
In short: shell for automation, scripting, and admin; Compass for interactive exploration, pipeline-building, and schema/index analysis. Many developers use both against the same cluster — and Compass even embeds a mongosh pane so you can drop down to the shell when needed.
Follow-up 1
What factors influence your choice between MongoDB Shell and Compass?
Several factors can influence the choice between MongoDB Shell and Compass:
Level of control and flexibility: If you need more control and flexibility, MongoDB Shell is the preferred choice as it allows you to write custom scripts and perform advanced operations.
Visual representation: If you prefer a visual representation of your data, MongoDB Compass provides an intuitive GUI for exploring and analyzing your data.
Task complexity: For simple tasks like querying and basic data manipulation, MongoDB Compass can be more convenient. However, for complex tasks that require scripting or automation, MongoDB Shell is more suitable.
Personal preference: Some users may have a personal preference for command-line interfaces or graphical interfaces, which can also influence their choice between MongoDB Shell and Compass.
Follow-up 2
How do you decide when to use MongoDB Stitch?
MongoDB Stitch is a serverless platform provided by MongoDB that allows you to build applications without managing infrastructure. It provides a set of services and features, such as authentication, database access, and serverless functions.
You can decide to use MongoDB Stitch based on the following factors:
Serverless architecture: If you want to build serverless applications and avoid managing infrastructure, MongoDB Stitch is a good choice.
Rapid development: MongoDB Stitch provides a set of pre-built services and features that can accelerate application development.
Scalability: MongoDB Stitch automatically scales your application based on demand, allowing you to handle high traffic and workload without worrying about infrastructure management.
Integration with MongoDB: If you are already using MongoDB as your database, MongoDB Stitch provides seamless integration and simplifies the development process.
Overall, the decision to use MongoDB Stitch depends on your application requirements, development preferences, and the need for serverless architecture.
Follow-up 3
Can you give an example of a task that can be performed in both MongoDB Shell and Compass, and explain why you would choose one over the other?
One example of a task that can be performed in both MongoDB Shell and Compass is querying the database.
If you have a simple query that you want to execute and analyze the results visually, MongoDB Compass can be a good choice. It provides a user-friendly interface for building queries using a visual query builder, and you can see the results in a tabular format.
On the other hand, if you have a complex query that requires aggregation, joins, or custom JavaScript functions, MongoDB Shell is more suitable. It allows you to write complex queries using the MongoDB Query Language (MQL) and provides more flexibility in terms of data manipulation and analysis.
In summary, MongoDB Compass is preferred for simple queries and visual analysis, while MongoDB Shell is preferred for complex queries and advanced data manipulation.
Live mock interview
Mock interview: MongoDB Shell, Compass, and Stitch
- Read your scene and goals
- Talk it out; goals tick off live
- Get a score and stronger lines
Your voice and your AI key never touch our servers; the key stays in this browser and is sent only to Google. Only your round scores are saved to track progress.