How to delete document using MongoDB Compass console


MongoDB can be used locally or hosted on cloud , in any case MongoDB Compass is a great tool for managing collections.

Compass come with a console, which you can use manipulate docs. Let’s learn how to explore and delete documents in a collection

Delete all documents

we can delete all documents using the following on terminal/ Compass console

use myDB
db.users.find()  -- list all users docs
db.users.deleteMany({})
db.users.find()  -- check again 

Here myDB is my Database and users is one of collection inside it. You can also use filter to delete many documents, for example delemany({uid:1001})

You may also love to read following tutorials

Published by

Manoj

A developer,teacher and a blogger obsessed with Python,Dart and open source world from India

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.