MongoDB 中的子查询用于检索课程详细信息

发布于 2025-01-10 11:54:29 字数 1320 浏览 0 评论 0原文

我有两个文档:

db.COURSE.insertMany([
                {"Course_name" : "Intro to Computer Science",
                "Course_number": "CS1310",
                "Credit_hours" :  4,
                "Department"   : "CS"
                },
                {"Course_name" : "Data Structures",
                "Course_number": "CS3320",
                "Credit_hours" :  4,
                "Department"   : "CS"
                },
                {"Course_name" : "Discrete Mathematics",
                "Course_number": "MATH2410",
                "Credit_hours" :  3,
                "Department"   : "MATH"
                },
                {"Course_name" : "Database",
                "Course_number": "CS3380",
                "Credit_hours" :  3,
                "Department"   : "CS"
                }
])
db.PREREQUISITE.insertMany([
                            {
                            "Course_number":"CS3380",
                            "Prerequisite_number":["CS3320","MATH2410"]
                            },
                            {
                            "Course_number":"CS3320",
                            "Prerequisite_number":"CS1310"
                            }
])

我想查询以检索“数据库”先决条件的 course_name 课程。

我们如何在 Mongo DB 中使用子查询?

I have two documents:

db.COURSE.insertMany([
                {"Course_name" : "Intro to Computer Science",
                "Course_number": "CS1310",
                "Credit_hours" :  4,
                "Department"   : "CS"
                },
                {"Course_name" : "Data Structures",
                "Course_number": "CS3320",
                "Credit_hours" :  4,
                "Department"   : "CS"
                },
                {"Course_name" : "Discrete Mathematics",
                "Course_number": "MATH2410",
                "Credit_hours" :  3,
                "Department"   : "MATH"
                },
                {"Course_name" : "Database",
                "Course_number": "CS3380",
                "Credit_hours" :  3,
                "Department"   : "CS"
                }
])
db.PREREQUISITE.insertMany([
                            {
                            "Course_number":"CS3380",
                            "Prerequisite_number":["CS3320","MATH2410"]
                            },
                            {
                            "Course_number":"CS3320",
                            "Prerequisite_number":"CS1310"
                            }
])

I wanted to query to retrieve the course_name of the prerequisites of the “Database”
course.

How can we use subquery in Mongo DB??

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

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

发布评论

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