Javascript required
Skip to content Skip to sidebar Skip to footer

Delete All Documents in Collection Mongodb Compass

MongoDB Compass is the official GUI for MongoDB, maintained by MongoDB itself. MongoDB Compass helps users make clever decisions about the data structure, querying, indexing, and many more actions you can perform on the database.

The primary objective of this article is to guide users who are new to MongoDB to perform database operations conveniently using MongoDB Compass.

(This article is part of our MongoDB Guide. Use the right-hand menu to navigate.)

What is MongoDB Compass?

MongoDB Compass is a GUI to explore, analyze, and interact with the content stored in a MongoDB database without knowing or using queries.

Compass a GUI alternative to the Mongo shell, which we've previously discussed. MongoDB Compass is an open-source tool. You can find its GitHub repository here.

What can you do with MongoDB Compass?

MongoDB Compass is a much better alternative for the Mongo shell. Compass can carry out all the operations that Mongo Shell does and more, including:

  • Visualize and explore data stored in your database
  • Create databases and Insert, update, and delete data in your database
  • Get immediate real-time server statistics
  • Understand performance issues with visual explain plans
  • Manage your indexes
  • Validate your data with JSON schema validation rules
  • Extendable via plugins

You can enjoy the benefits of MongoDB's powerful features by installing the full version of Compass. It's free to use for everyone and will make working with MongoDB easier than any other tool.

Now, let's install MongoDB Compass.

Installing MongoDB Compass

It's important to note that MongoDB Compass comes in three editions:

  • Compass has the full capabilities and features of MongoDB Compass.
  • Compass Read-Only is limited to the read operations. You won't have the capability to edit, write, or delete.
  • Compass Isolated does not involve any requests for the network.

MongoDB Compass

Most of the time, it's the full edition that you need, so that's what we'll install in this tutorial. MongoDB supports all the main operating systems, such as:

  • Windows
  • Ubuntu
  • OS X
  • RedHat

Download the packages you want here. Once you download the relevant package, run the installer, and follow the steps that come after it.

Connecting to a database

First, open your MongoDB Compass application and click the Fill in connection fields individually option. Specify the Hostname and the port in which your MongoDB server is running. If you installed MongoDB on your machine with default settings, the Hostname would be the localhost, and the port is 27017. Then click CONNECT.

New Connection

Now, you are connected to your MongoDB server. You can see a list of databases available in the server and a set of options that you can use to create and delete databases:

Database

Creating databases, collections, and inserting data

Click the CREATE DATABASE option to create a new database. A new window will pop up, as shown below:

  • Enter the Database name (e.g., School)
  • Enter a Collection name (e.g., Students).
  • Click on the CREATE DATABASE

Create Database

The newly created database will appear in the dashboard, as shown below.

Database Name

(Want to use the mongo shell instead of the Compass GUI? Learn how to create a database that way.)

Creating documents

In MongoDB, data is inserted as documents. Each record in a MongoDB database is a document. Let's see how to add documents to our newly created database.

Locate the cursor on the School database from the left side pane of Compass and click on it. A screen will be displayed as below:

Creating documents

Next, click on the collection name, Students, which you created earlier, and Compass will display a new screen, like this:

Student Screen

Here you can find the Add Data drop-down that provides you two ways to insert data:

  • By importing a JSON/CSV file
  • By adding data manually

The first option allows you to import data as a JSON or CSV file. When you click it, a new window will open in which you can upload the file. Browse and upload the file there, then tick the relevant file type and click import.

Import

In order to add data manually, click on the second option of the Add Data dropdown. A Helper window will pop up to insert documents. You can add values as JSON or key-value pairs in this Helper window.

Import to Collection

Finally, click the Insert button.

Local Documents

Inserting more documents

Although you can insert more documents in the same way as we just discussed, we can speed it up with the Clone operation.

Hover over the newly created data in the Compass UI and click the Clone Document button. This option will copy the data into a new Insert Document window. From there, you just have to type the next row of data, and there's no need to specify the field names or data types again.

School Documents

Likewise, you can keep on adding any amount of data to the collection, and those data will show up on the Compass UI.

Compass UI

Viewing data (documents)

Compass lets you view your data in three modes. The modes are as follows:

  • List view
  • JSON view
  • Table view

You can change the view by clicking the buttons next to the view option, as shown here:

Viewing data

Updating documents

Updating documents through Compass is straightforward. Hover over the document you want to update in the Compass and click on the pencil icon, which appears on the right-hand side.

Add Data Update

Click on the field you need to update, then update as required, and click the Update button.

Update Data

Deleting documents

Deleting data is another simple task that Compass can do with just two clicks:

  1. Hover over the document you want to delete.
  2. Click on the trash icon, located on the right-hand side:

Delete Data

Dropping collection and database

Dropping collections and databases are as straightforward as other operations. You can find all your databases and collections appearing on the left menu of Compass. There you can find options to drop collections and databases. The image below shows both options.

Dropping Collection

That concludes this tutorial.

Additional resources

For more tutorials like this, explore these resources:

  • BMC Machine Learning & Big Data Blog
  • MongoDB Guide, a series of tutorials
  • How To Query JSON Data in Snowflake
  • MongoDB vs Cassandra: NoSQL Databases Compared
  • How To Connect Amazon Glue to a JDBC Database

Free E-book: The Beginner's Guide to MongoDB

MongoDB is the most popular NoSQL database today and with good reason. This e-book is a general overview of MongoDB, providing a basic understanding of the database.


These postings are my own and do not necessarily represent BMC's position, strategies, or opinion.

See an error or have a suggestion? Please let us know by emailing blogs@bmc.com.

BMC Bring the A-Game

From core to cloud to edge, BMC delivers the software and services that enable nearly 10,000 global customers, including 84% of the Forbes Global 100, to thrive in their ongoing evolution to an Autonomous Digital Enterprise.
Learn more about BMC ›

You may also like

About the author

Shanika Wickramasinghe

Shanika Wickramasinghe is a software engineer by profession and a graduate in Information Technology. Her specialties are Web and Mobile Development. Shanika considers writing the best medium to learn and share her knowledge. She is passionate about everything she does, loves to travel, and enjoys nature whenever she takes a break from her busy work schedule. You can connect with her on LinkedIn.

Delete All Documents in Collection Mongodb Compass

Source: https://www.bmc.com/blogs/mongodb-compass/