> For the complete documentation index, see [llms.txt](https://www.0xmrjane.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.0xmrjane.com/mongodb.md).

# MongoDB

#### คำสั่ง SQL VS MONGO

| SQL      | MongoDB  |
| -------- | -------- |
| WHERE    | $match   |
| GROUP BY | $group   |
| SELECT   | $project |
| ORDER BY | $sort    |
| LIMIT    | $limit   |
| JOIN     | $lookup  |

#### การสร้างและลบฐานข้อมูล

* การแสดงฐานข้อมูล

cmd

```
show dbs
```

* การสร้าง หรือ เลือกฐานข้อมูล

cmd

```
use dbName
```

(หากมี db อยู่แล้วจะเป็นการเรียกใช้ แต่ถ้าหากไม่มี จะเป็นการสร้างขึ้นมาแทน)

* การลบฐานข้อมูล

cmd

```
db.dropDatabase()
```

(ต้องอยู่ในฐานข้อมูลนั้นก่อนเช่น `use staff` ตามด้วย `db.dropDatabase`)

#### การจัดการ Collection

* การสร้าง Collection

cmd

```
db.createCollection("CollectionName")
```

* การแก้ไขชื่อ Collection

cmd

```
db.collectionName.renameCollection("newCollectionName")
```

* การลบ Collection

cmd

```
db.collectionName.drop()
```

#### ชนิดข้อมูลใน Mongodb

| ชนิดข้อมูล | รายละเอียด |
| :--------: | ---------- |
|   String   |            |
|            |            |
|            |            |
