收集文件1
{
"_id" : ObjectId("5c2ee03224acf45a663d8f09"),
"_class" : "document.domain.DDD",
"generated" : false,
"linkIds" : [],
"types" : [],
"metadata" : {
"templateId" : "ABDC",
"userId" : "Master"
}
"versions" : [
{
"revision" : "fb4fb8ec-edfe-4a3e-a1a9-c8c4b2bce678",
"fileId" : "5c2ee03224acf45a663d8f08"
}
]
}
collection B document 1
{
"_id" : ObjectId("5c2ee03224acf45a663d8f08"),
"_class" : "document.domain.RDF",
"extension" : ".pdf",
"rootPath" : "D"
"size" : 152754
}
集合A,文档1中的字段ID在集合B doc 1的objectid中显示为字符串。
如何在集合B中查找显示为objecid的字符串?
答案 0 :(得分:0)
您必须在那里使用mongodb聚合 你有更多的看法 https://docs.mongodb.com/manual/core/aggregation-pipeline/ 并且您必须使用$ lookup运算符更多了解 https://docs.mongodb.com/manual/reference/operator/aggregation/lookup/
您可以完成此任务
collectionA.aggregate.([
{
$match:{},// To match and get all doc
},
{
$lookup:
{
from: collection B//<collection to join>,
localField: versions.fileId//<field from the input documents>,
foreignField: _id//<field from the documents of the "from" collection>,
as: versions.file//<output array field>
}
}])