微信小程序 云开发

store 商品集合


_id: 'a8831daa5fef02f50153146e5902c2aa',
openid: 'oMlDj5JiYiwxyBJm-d4JFY-Ov-LM', // 发布商品者 openid
title: '小米手电筒',
liulan: 29,
price: 19.9,
imgUrl: 'xxxxxxxxxxxxxxxx',
time: 1609499381638,
shenhe: true,


fav 收藏集合


_id: 'b45a21d55ff155e2036603d6218fa777',
_openid: 'oMlDj5JiYiwxyBJm-d4JFY-Ov-LM',    // 收藏者 openid
fav_id: 'a8831daa5fef02f50153146e5902c2a1'  // 收藏的商品 _id

fav 集合记录数量 = store 商品集合记录数量 * 所有商品总收藏数量

会产生 超级多 的记录


联表查询 (我收藏的.wxml)云函数代码

function getfavlist(event, context) {
  return new Promise(function (resolve, reject) {
    db.collection("fav")
      .aggregate()
      .lookup({
        from: "store",
        localField: "fav_id",
        foreignField: "_id",
        as: "storedetail",
      })
      .match({
        _openid: event.userInfo.openId,
      })
      .end()
      .then((res) => {
        console.log(res);
        resolve(res);
      })
      .catch((err) => console.error(err));
  });
}

在这里插入图片描述在这里插入图片描述


感觉把 微信小程序 云开发 文档型数据库 用成了关系型数据库

还可以给 store 商品集合 下的所有记录 新增 fav_openid 字段 (一个数组存储 收藏者的 openid)


_id: 'a8831daa5fef02f50153146e5902c2aa',
openid: 'oMlDj5JiYiwxyBJm-d4JFY-Ov-LM', // 发布商品者 openid
fav_openid: ['小明的 openid', 'Tom 的 openid', '马保国的 openid'],
title: '小米手电筒',
liulan: 29,
price: 19.9,
imgUrl: 'xxxxxxxxxxxxxxxx',
time: 1609499381638,
shenhe: true,

这样看上去 store 商品集合存储空间会比较大?


试试这样?

fav 收藏集合


_id: 'b45a21d55ff155e2036603d6218fa777',
_openid: 'oMlDj5JiYiwxyBJm-d4JFY-Ov-LM',                                    // 收藏者 openid
fav_openid: ['小明的 openid', 'Tom 的 openid', '马保国的 openid'],

fav 集合记录数量 = store 商品集合记录数量


推荐一下刚上线的 App 熊猫小账本。

熊猫小账本 一个简洁的记账 App,用于记录日常消费开支收入,使用 iCloud 保存同步数据。

  • 支持备注,自定义时间偶尔忘记记账也没关系。
  • 搜索历史记账,支持分类、金额、备注。
  • 启动时需要面容/指纹验证,保护个人隐私。
  • 支持自定义分类功能,自由添加修改分类。
  • 统计图表,支出收入一目了然。
  • 每天提醒记账,不会有其他推送。
  • 桌面锁屏小组件开发中。。。