

Using the Mongo DB Shell to remove all elements in a collection
source link: https://www.pmichaels.net/2021/06/19/using-the-mongo-db-shell-to-remove-all-elements-in-a-collection/?utm_campaign=using-the-mongo-db-shell-to-remove-all-elements-in-a-collection
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Using the Mongo DB Shell to remove all elements in a collection
In my recent experiments with using MongoDB, I came across a need to remove all the records from a collection – the equivalent of DELETE FROM MYTABLE in SQL.
It turns out that, in order to do this, you need to use the Mongo DB Shell. This comes with Compass, although you may miss it, tucked away at the bottom:
By default it’s collapsed, but once you un-collapse it, you can do a number of things. The first thing you should do is tell it which DB you would like to use (for the purpose of this, let’s assume the database is called aardvark):
> use aardvark
< 'switched to db aardvark'
You can see which collections you have in the database, like this:
> db.getCollectionNames()
< [ 'collection1', 'collection2' ]
You can also see some information about a specific collection; for example:
> db.collection1.exists()
This should return a JSON document that details collection1.
In my case, I wanted to clear everything from the collection:
> db.collection1.deleteMany({ })
You can also pass this a specific filter, but this allows you to delete everything.
References
Recommend
-
18
一、题目 删除链表中等于给定值 val 的所有节点。 示例: 输入: 1->2->6->3->4->5->6, val = 6 输出: 1->2->3->4->5 二、题解 解法1...
-
7
Tutorial How To Perform CRUD Operations in MongoDB Using PyMongo on Ubuntu 20.04 MongoDB
-
5
In this tutorial we will learn about adding & subrtacting two Series objects and then how to remove elements from Series. Table Of Contents Adding/Merging Series together In Pandas, the Series provides a function...
-
8
mongo 基本的 shell 指令 因為是開發 nodejs ,最常用到的資料庫就是 mongo ,不過最近都在開發前端,太久沒有碰觸到他了,今天就來複習一下吧。 進入 mongo # mongo 結果他...
-
10
Not FoundYou just hit a route that doesn't exist... the sadness.LoginRadius empowers businesses to deliver a delightful customer experience and win customer trust. Using the LoginRadius Identity...
-
6
This article was published as a part of the Data Science Blogathon. Introduction on Mongo DB In the first part of this article,...
-
7
Remove elements from NumPy Array by Index In this article, we will learn how to remove elements from a Numpy Array by index position. Table Of Contents Given a NumPy array...
-
6
mongo在shell命令行直接执行js脚本 精选 原创 雍州无名 2022-09-08 08:17:00
-
4
Are you using the right Mongo geospatial query? By Roop Feb 10, 2023 We recently got a...
-
8
This tutorial will discuss multiple ways to remove elements from list using pop() method in Python. Table Of Contents Delete Element at given Index in Lis...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK