Golang – Backend (Sprint1)
contributed by < ArielWu0203
>
GitHub : pd1-learning
Goal
Install the MongoDB Go Driver
Connect to DB
-
context
- context switch : 當使用權要從 A process 交給 B process 時,A process 的狀態需要被保存下來,記錄在 PCB 中,再載入 B process 。
- context.Background() :
- 已先初始化。
- return non-nil, empty Context.
- No canceled, No value, No deadline.
- 通常用在 main function, top-level Context, parent Context.
- context,TODO() :
- 已先初始化。
- return non-nil, empty Context.
- 不清楚、不確定時才使用。
- More links
-
Collection
Insert Documents
FindOneDoc
- BSON Objects
- Binary-encoded JSON
- Type :
- D: A BSON document. This type should be used in situations where order matters, such as MongoDB commands.
- M: An unordered map. It is the same as D, except it does not preserve order.
- A: A BSON array.
- E: A single element inside a D.
FindAllDocs
Reference