我有这样的数据结构
Courses
{
"name" : "Course1",
"student_id"
"subjects" :
[{
"level" : "1",
"short_name" : "Maths",
"topics" : [{
"name" : "Algebra 101",
"week" : "1",
"submission_week" : ISODate("2013-07-28T00:00:00Z"),
"correction_week" : ISODate("2013-07-28T00:00:00Z")
},
{
"name" : "Algebra 201",
"week" : "1",
"submission_week" : ISODate("2013-07-28T00:00:00Z"),
"correction_week" : ISODate("2013-07-28T00:00:00Z")
}
]},
{
"level" : "2",
"short_name" : "Chem"
}
]
}
使用 Mongoid 我正在尝试检索所有主题。
我尝试了各种查询,但似乎无法得到它。
例如,我不明白为什么这不起作用?
Topic.where( name: "Algebra 101", 'subject.short_name' =>"Maths", 'subject.course.name' =>"Course1")
我可以这样查询吗?
我的红宝石代码是
class Course
embeds_many :subjects
class Subject
embedded_in :course
embeds_many :topics
class Topic
embedded_in :subject