Suppose I have two collection in a mongoDB
students:
{_id: 1, name: "sa", teachers:[1,2,3]}
{_id: 2, name: "sb", teachers:[1,3]}
teachers:
{_id:1, name: "ta"}
{_id:2, name: "tb"}
{_id:3, name: "tc"}
now I want to query in students collection through teachers name. Like this:
db.students.find({'teachers.name':"ta"}).count()
I have read somewhere that it is possible to link collection or embed it. Is there any way to do it?
what have I tried? I have tried db.students.ensureIndex({'teachers':1}) but it does not work. I also think it should not work. I am going out of clue how to do it?
DUPLICATE: Well I know that there are a lot of post which has similar title, but yet I am confused!