3.3.11.Building support for Partial Responses
Last updated
Last updated
Partial Responses
"API consumer" in control of response
例如mobile的使用者可能不需要取得完整的資料, Partial Responses可以讓使用者指定特定的欄位
Benefits
Better performance & optimized resource usage
CPU, Memory, Bandwidth
API consumer controls the granularity
Common API version for all consumers
to support multiple devices, use cases - form factors
Specifiction
Depends on the platform/language/DB
Linkedin: /people: (id, first-name, last-name)
facebook: /friend?fields=id,name,picture
Pinterest: /pins?fields=id,link,creator(first_name)
Requirements
Add collection -> 新增一個叫hotels的collection
Add database user -> 新增一個叫xxx的user
collection-> index -> add index
{ "name": 1}, 勾選unique
1.clone repository
2.將資料寫到DB
設定連線字串
到mlab的database頁面下, 複製連線字串
開啟專案, 修改tests/TestHotelsDBOps.js的process.env.DB_URI
開啟檢視/ 偵錯主控台/ 終端機, 輸入
3.程式碼解析
mongoDB的作法是用projection