猫鼬加剧

发布于 2025-02-12 10:00:21 字数 467 浏览 0 评论 0原文

我看到了很多类似的问题和答案,但是我有点困惑。

如何通过猫鼬的汇总来实现这一目标?

const userId = "23523891729417419";

const students = await Students.find({ active: true });
const courses = await Courses.find({ userId: userId });

const result = students.filter((s) => {
    const found = courses.find((c) => c.someId === s.someOtherId);
    if (!found) return s;   
});

在两个模型中,有一个字段(具有不同的名称),在某些文档上,它们的值可能相等。我想将它们排除在结果之外。

学生和课程只是虚拟的名字。并可能会弄乱这个问题。

I have seen so many similar questions and answers, but and I'm a bit confused.

How can I achieve this with aggregate in mongoose?

const userId = "23523891729417419";

const students = await Students.find({ active: true });
const courses = await Courses.find({ userId: userId });

const result = students.filter((s) => {
    const found = courses.find((c) => c.someId === s.someOtherId);
    if (!found) return s;   
});

There is one field (with differnet names) in both models that on some documents the value of them might be equal. I want to exclude them from result.

students and courses are just dummy names. and might mess with the question.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文