add the old snippet md files
This commit is contained in:
parent
fc0dd204c7
commit
bcf8313a4b
110 changed files with 3048 additions and 0 deletions
35
old_snippets/wipe-mongo-collection.en.md
Normal file
35
old_snippets/wipe-mongo-collection.en.md
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
---
|
||||
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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue