云函数连表查询语句问题?

小程序 文章 2021-04-04 16:42 394 0 全屏看文

AI助手支持GPT4.0

云函数连表查询语句问题?Is there a problem with cloud function table query?

云函数连表查询语句问题?

有两张表 ,一个是问题表,一个是收藏表,怎么在查询的时候查出这个问题表里用户是否收藏过,查询要做分页的

There are two tables, one is the problem table and the other is the collection table. How to find out whether the user has collected the problem table during the query? The query should be paginated

回答:

གངས་ཁྲུང:1234
شەرەر:

lookup 连起来就可以。

let OPENID = '用户 OpenID';let count = 20; // 获取数据数量let page = 1; // 获取数据的页面号// 文章表为:articles,收藏表为:saves。let res = await db.collection("saves").aggregate().project({ _id: 0 })    .match({ _openid: OPENID }).limit(count).skip((page - 1) * count)    .lookup({      from'articles',      localField: '_article',      foreignField: '_id',      as'list'    })    .replaceRoot({      newRoot: $.mergeObjects([ $.arrayElemAt(['$list'0]), '$$ROOT' ])    })    .project({ list: 0 })    .end();
🌟:我知道是这个 没写出来
Eric:那把代码贴出来啊,否则这么回答

-EOF-

AI助手支持GPT4.0