35 lines
1 KiB
Markdown
35 lines
1 KiB
Markdown
---
|
|
title: "wipe a mongo collection"
|
|
date: 2020-06-29T10:32:01+02:00
|
|
draft: false
|
|
snippet_types: ["mongo"]
|
|
---
|
|
|
|
Currently I run a shared mongo instance in my k8s cluster used by a bunch of my side projects.
|
|
Every once in a while I have to manually execute mongo commands this is how I do so.
|
|
|
|
Manually ssh into the pod:
|
|
|
|
```shell
|
|
$ kubectl exec -it shared-mongo-xxxxxxxxxx-xxxxx -- /bin/bash
|
|
```
|
|
|
|
Then launch the mongo shell and hack away:
|
|
|
|
```shell
|
|
$ mongo
|
|
> db2 = db.getSiblingDB('coolDB')
|
|
coolDB
|
|
> db2.getCollectionNames()
|
|
[ "coolThings" ]
|
|
> db2.coolThings.count()
|
|
666
|
|
> db2.coolThings.remove({})
|
|
WriteResult({ "nRemoved" : 666 })
|
|
> db2.coolThings.count()
|
|
0
|
|
```
|
|
|
|
source:
|
|
- [stackoverflow -- mongodb-how-to-delete-all-records-of-a-collection-in-mongodb-shell](https://stackoverflow.com/questions/46368368/mongodb-how-to-delete-all-records-of-a-collection-in-mongodb-shell)
|
|
- [stackoverflow -- how-can-i-list-all-collections-in-the-mongodb-shell](https://stackoverflow.com/questions/8866041/how-can-i-list-all-collections-in-the-mongodb-shell)
|