之前玩过oracle,mysql数据库,这些都是关系型的数据库,而微信的云数据库是文档型的,具体来说是JSON 数据库。参见官网:链接
关系型数据库和 JSON 数据库的概念对应关系如下表:
关系型 | 文档型 |
---|---|
数据库 database | 数据库 database |
表 table | 集合 collection |
行 row | 记录 record / doc |
列 column | 字段 field |
文档型的数据库中的字段既可以是字符串或数字,还可以是对象或数组,就是一个 JSON 对象。这就是说关系型数据库通过子表才能实现的一对多,在文档型数据库中通过主表的一个字段是数组的方式就能轻松实现。
先期先完成最最基本的功能,连操作记录都不处理。设计下来两个集合就足够了,clients和targets。
clients集合存放的就是微信小程序的使用用户
{
"_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": "早起的鸟儿有虫吃"
}