> 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 }
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://kawsing.gitbook.io/opensystem/andoid-shou-ji/mongodb-community/on-debian-shi-yong.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
