I am a newbie to DocumentDB. Trying to join two collections and perform filters like query, sort and projection.
I have two collections and need to perform filters on both the collections and the result should be a embeded list (Which should contain both items and subitems).
First collection will hold the id's of the second collection in a Subitems field.
Here is the first collection (Items):
{
"_id": 897979789,
"Country": "India",
"State": "XXX",
"Subitems": [ ObjectId("44497979789"), ObjectId("333897979789") ]
},
{
"_id": 987979798,
"Country": "Australia",
"State": "YYY",
"Subitems": [ ObjectId("97979789444"), ObjectId("897979789333") ]
}
Here is the second collection:
{
"_id": 44497979789,
"EmployeeName": "Krishna",
"Occupation": "Engineer",
"ProjectsHandled": [
{
"ProjectName": "Project1"
}
]
},
{
"_id": 333897979789,
"EmployeeName": "krish",
"Occupation": "CTO",
"ProjectsHandled": [
{
"ProjectName": "Project1"
}
]
},
{
"_id": 97979789444,
"EmployeeName": "name",
"Occupation": "CEO",
"ProjectsHandled": [
{
"ProjectName": "Project2"
}
]
},
{
"_id": 897979789333,
"EmployeeName": "name1",
"Occupation": "manager",
"ProjectsHandled": [
{
"ProjectName": "Project3"
}
]
}
Here is my query:
let subItemPipeline: any[] = [{ $match: config.subItemsQuery }];
if(Object.keys(config.subItemsSort || {}).length)
subItemPipeline.push({$sort: config.subItemsSort});
if(Object.keys(config.subItemsProjection || {}).length)
subItemPipeline.push({$project: config.subItemsProjection});
let query: any[] = [
{
$match: config.itemsQuery
},
{
$lookup: {
from: "Subitems",
pipeline: subItemPipeline,
as: "Subitems"
}
}
];
if(Object.keys(config.overallQuery || {}).length) query.push({$match: config.overallQuery});
if(Object.keys(config.itemsSort || {}).length) query.push({$sort: config.itemsSort});
if(Object.keys(config.itemsProjection || {}).length) query.push({$project: config.itemsProjection});
const items = await collection.aggregate(query).toArray();
It is working fine in MongoDB, but am facing the following error in DocumentDB:
Mongoerror: aggregation stage not supported: '$lookup on multiple join conditions and uncorrelated subquery
Any assistance will be appreciated