微信小程序 lookup 联表查询
微信小程序 云开发
store 商品集合
_id: a8831daa5fef02f50153146e5902c2aa, openid: oMlDj5JiYiwxyBJm-d4JFY-Ov-LM, // 发布商品者 openid title: 小米手电筒, liulan: 29, price: 19.9, imgUrl: xxxxxxxxxxxxxxxx, time: 1609499381638, shenhe: true,
会产生 超级多 的记录
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 集合记录数量 = store 商品集合记录数量
喜欢或对你有帮助,请点个赞吧 。
有错误或者疑问还请评论指出。
我的个人网站 --> 。
END
上一篇:
uniapp开发微信小程序-2.页面制作
下一篇:
用微信小程序做H5游戏尝试
