我无法检索集合中数组中引用的所有文档。我不知道该怎么办。你能帮我吗?
这是我的收藏,那里有id
/* 1 */
{
"_id" : ObjectId("60a3b4c2e4ff64f92f0dd70b"),
"desigantion" : "UE1",
"coefficent" : 15,
"matieres" : [
ObjectId("60a3b356e4ff64f92f0dd1fc"),
ObjectId("60a3b856e4ff64f92f0de49b"),
ObjectId("60a3b8a0e4ff64f92f0de5dc"),
ObjectId("60a3b8eee4ff64f92f0de701"),
ObjectId("60a3b5ace4ff64f92f0ddaaa")
]
}
/* 2 */
{
"_id" : ObjectId("60a3b6dce4ff64f92f0ddf7f"),
"desigantion" : "UE2",
"coefficent" : 15,
"matieres" : [
ObjectId("60a3b67ee4ff64f92f0ddde3"),
ObjectId("60a3ba8be4ff64f92f0dee6f"),
ObjectId("60a3b629e4ff64f92f0ddcd5")
]
}
这是我收藏的";matieres";
/* 1 */
{
"_id" : ObjectId("60a3b5ace4ff64f92f0ddaaa"),
"nom" : "C++",
"professeurs" : [
{
"nom" : "Jardin",
"prenom" : "Pierre"
},
{
"nom" : "LaStreet",
"prenom" : "Bernard"
},
{
"nom" : "Boiserie",
"prenom" : "Theo"
}
],
"coefficient" : 2
}
/* 2 */
{
"_id" : ObjectId("60a3b629e4ff64f92f0ddcd5"),
"nom" : "Anglais",
"professeurs" : [
{
"nom" : "Michelle",
"prenom" : "Conry-Fidone"
}
],
"coefficient" : 6
}
/* 3 */
{
"_id" : ObjectId("60a3b67ee4ff64f92f0ddde3"),
"nom" : "PPP",
"professeurs" : [
{
"nom" : "Giraud",
"prenom" : "Laurent"
},
{
"nom" : "Luret",
"prenom" : "Marilyn"
}
],
"coefficient" : 2
}
/* 4 */
{
"_id" : ObjectId("60a3b856e4ff64f92f0de49b"),
"nom" : "Algo",
"professeurs" : [
{
"nom" : "Simon",
"prenom" : "Carine"
}
],
"coefficient" : 9
}
/* 5 */
{
"_id" : ObjectId("60a3b8a0e4ff64f92f0de5dc"),
"nom" : "Java",
"professeurs" : [
{
"nom" : "Hasbani",
"prenom" : "Abdel"
},
{
"nom" : "Provot",
"prenom" : "Laurent"
},
{
"nom" : "Bouhours",
"prenom" : "Cedric"
}
],
"coefficient" : 8
}
/* 6 */
{
"_id" : ObjectId("60a3b8eee4ff64f92f0de701"),
"nom" : "BDD",
"professeurs" : [
{
"nom" : "Lafourcade",
"prenom" : "Pierre"
},
{
"nom" : "Brigoulet",
"prenom" : "Pascale"
}
],
"coefficient" : 5
}
/* 7 */
{
"_id" : ObjectId("60a3ba8be4ff64f92f0dee6f"),
"nom" : "Economie",
"professeurs" : [
{
"nom" : "Goi",
"prenom" : "Isabelle"
}
],
"coefficient" : 5
}
/* 8 */
{
"_id" : ObjectId("60bf67e842ecdb7d4268cc7e"),
"nom" : "Maths",
"coefficient" : 5,
"professeurs" : [
{
"nom" : "Jean",
"prenom" : "Pierre"
},
{
"nom" : "LaStreet",
"prenom" : "Patrick"
},
{
"nom" : "Buisson",
"prenom" : "Jules"
}
],
"_class" : "fr.iut.blankproject.domain.Matiere"
}
/* 9 */
{
"_id" : ObjectId("60d1d9d364ccf255491679de"),
"nom" : "PPP2",
"professeurs" : [
{
"nom" : "Giraud",
"prenom" : "Laurent"
},
{
"nom" : "Luret",
"prenom" : "Marilyn"
}
],
"coefficient" : 6
}
我想把所有的主题都放在";指定=UE1";从";matieres";大堆谢谢
db.getCollection('mainCollection').aggregate([{
$match: {
desigantion: "UE1"
}
} {
$unwind: "$matieres"
},
{
$lookup: {
from: "matieres",
localField: "matieres",
foreignField: "_id",
as: "data"
}
}
])
以下是的步骤
- 从您的主集合中,我找到了所有符合条件
desigantion: "UE1"
的数据集 - 则我已尝试将密钥CCD_ 3 CCD_
- 最后,我使用了
$lookup
我的matieres
密钥来收集matieres