我有下面的代码来返回博客作者 ID 等于数组中第一个管理员 (orgAdmin) 的 ID 的所有博客:
let officialBlogs = await Blog.find().where('author.id').equals(help.orgAdmins[0]);
但我不知道如何调整此代码,以便我可以返回作者与数组中任何管理员匹配的博客(即 orgAdmin[0]、orgAdmin[1]、orgAdmin[2] 等。任何人都可以建议?
您可以使用$in
运算符根据传递的 id 获取内容,如下所示:
const ids = [];
help.orgAdmins.forEach(id => ids.push(id));
let officialBlogs = await Blog.find({author.id: { $in: ids }});
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句