I have these two collections.
collectionname : req
{
reqId: "A123",
status: "1",
location: "hyd"
}
collection name : reqUser
{
req: "A123"
userId: "U1787"
designation: "employee"
}
Need an aggregate filtering the req collection based on location as hyd & aggregating the user field based on reqId.
Need Like this:
{
reqId: "A123",
status: "1",
userId: "U1787"
}
I used query on req collection with $match to filter based on location & $project to display only required fields from req collection and $lookup to match the reqId's from both collection but the issue is I am getting the whole reqUser object.
I am getting Something like this:
{
reqId: "A123",
status: "1",
reqUser:[
{
req: "A123"
userId: "U1787"
designation: "employee"
}
]
}
I need only userId field. Can anyone help me with obtaining the data as per my requirement mentioned above. I am using mongo version 3.4.