在MongoDB中如何通过Id使用DBRef查找查询?

时间:2017-10-23 23:40:29

标签: mongodb

如何在MongoDB中使用DBRef通过Id查找查询?

学生收集的文件是:

{
    "_id" : ObjectId("59bc49ef962d7420843331b7"),
    "first_name" : "Anthony",
    "last_name" : "McKelly",
}
{
    "_id" : ObjectId("59bc49f0962d74198d421a6d"),
    "first_name" : "John",
    "last_name" : "Doe",
}
{
    "_id" : ObjectId("59bc49f0962d742048757807"),
    "first_name" : "Peter",
    "last_name" : "Parquer",
}
{
    "_id" : ObjectId("59bc49f0962d742048757818"),
    "first_name" : "Katy",
    "last_name" : "Jackson",
}
{
    "_id" : ObjectId("59bc49f0962d74204d270ff3"),
    "first_name" : "Mary",
    "last_name" : "Petrova",
}

这是Queue集合的一部分:

{
    "_id" : ObjectId("59bc49ef962d7420843331c6"),
    "student" : DBRef("students", ObjectId("59bc49ef962d7420843331b7"), "school"),
    "groupid" : "59aeda24962d740934127b82"
}
{
    "_id" : ObjectId("59bc49f0962d74198d421a7c"),
    "student" : DBRef("students", ObjectId("59bc49f0962d74198d421a6d"), "school"),
    "groupid" : "59aeda24962d740934127b82"
}
{
    "_id" : ObjectId("59bc49f0962d742048757816"),
    "student" : DBRef("students", ObjectId("59bc49f0962d742048757807"), "school"),
    "groupid" : "59aeda24962d740934127b82"
}
{
    "_id" : ObjectId("59bc49f0962d742048757827"),
    "student" : DBRef("students", ObjectId("59bc49f0962d742048757818"), "school"),
    "groupid" : "59aeda24962d740934127b82"
}
{
    "_id" : ObjectId("59bc49f0962d74204d271002"),
    "student" : DBRef("students", ObjectId("59bc49f0962d74204d270ff3"), "school"),
    "groupid" : "59aeda24962d740934127b82"
}

我需要知道如何使用查询访问Queue集合中DBRef的学生数据。

这不起作用:

db.queue.find({student.id : '59bc49ef962d7420843331b7' })
db.queue.find({student._id : ObjectId("59bc49f0962d742048757807") }) 

请帮助我,我非常感激。

0 个答案:

没有答案