> For the complete documentation index, see [llms.txt](https://kawsing.gitbook.io/opensystem/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kawsing.gitbook.io/opensystem/andoid-shou-ji/mongodb-community/on-debian-shi-yong.md).

# on Debian 基本使用

## 使用預設路徑(/etc/mong.conf)

### /var/lib/mongodb

```
service mongod start
```

### 進入 REPL (Read-Evai-Print-Loop)互動命令列

```
mongo
>
```

### 顯示資料庫

```
>show dbs
> db
test #預設資料庫物件
> use mydatabase #使用mydatabase，沒有會自動建立
switched to db mydatabase
> db
mydatabase
```

### 插入一列資料，會自動建立資料表(集合) ：class100，插入JSON檔案

```
>db.class100.insert({"stu":1,"name":"王小明","age":13})
WriteResult({ "nInserted" : 1 })
>show dbs
admin       0.000GB
config      0.000GB
local       0.000GB
mydatabase  0.000GB
```

### 顯示資料表

```

> show collections
class100
```

### 顯示JSON資料

```
> db.class100.insert({"stu":2,"name":"林小美","age":13})
WriteResult({ "nInserted" : 1 })
> db.class100.find()
{ "_id" : ObjectId("5de6fef4ea717dbacb7553c6"), "stu" : 1, "name" : "王小明", "age" : 13 }
{ "_id" : ObjectId("5de6fff8ea717dbacb7553c7"), "stu" : 2, "name" : "林小美", "age" : 13 }
#_id為預設主鍵，會自動補上
```

### 找出需要的資料

```
> db.class100.find({"stu":1})
{ "_id" : ObjectId("5de6fef4ea717dbacb7553c6"), "stu" : 1, "name" : "王小明", "age" : 13 }
> db.class100.find({"name":"林小美"})
{ "_id" : ObjectId("5de6fff8ea717dbacb7553c7"), "stu" : 2, "name" : "林小美", "age" : 13 }
```
