以前玩過oracle,mysql數據庫,這些都是關係型的數據庫,而微信的雲數據庫是文檔型的,具體來講是JSON 數據庫。參見官網:連接html
關係型數據庫和 JSON 數據庫的概念對應關係以下表:mysql
關係型 | 文檔型 |
---|---|
數據庫 database | 數據庫 database |
表 table | 集合 collection |
行 row | 記錄 record / doc |
列 column | 字段 field |
文檔型的數據庫中的字段既能夠是字符串或數字,還能夠是對象或數組,就是一個 JSON 對象。這就是說關係型數據庫經過子表才能實現的一對多,在文檔型數據庫中經過主表的一個字段是數組的方式就能輕鬆實現。sql
先期先完成最最基本的功能,連操做記錄都不處理。設計下來兩個集合就足夠了,clients和targets。數據庫
clients集合存放的就是微信小程序的使用用戶json
{ "_id": "b758fc63-ad4a-4aa2-92ea-09dd5c0417a2", "name": "wxx", "nickName": "Simon", "age": 30.0, "initDate": { "$date": "2019-05-31T14:18:16.089Z" }, "status": "ON", "_openid": "", "lastLoginDate": { "$date": "2019-08-25T03:24:21.831Z" } }
targets集合中存放的是目標和打卡記錄,其中打卡記錄是目標的一個集合。經過client_id或者_openid來關聯clients集合中的某一個client。小程序
{ "_id": "2dd7a4fa-be43-410d-8d60-6d61f39e4db2", "client_id": "b758fc63-ad4a-4aa2-92ea-09dd5c0417a2", "name": "早起", "trackList": [ { "location": { "coordinates": [ 12.0, 12.0 ], "type": "Point" }, "checkInDate": { "$date": "2019-05-31T14:26:21.776Z" } } ], "_openid": "", "createDate": { "$date": "2019-06-30T14:21:38.000Z" }, "completeDate": { "$date": "2019-05-31T14:21:17.075Z" }, "status": "PROCESSING", "period": [ 1.0, 2.0, 3.0 ], "comment": "早起的鳥兒有蟲吃" }