I have two MongoDB Tabel
App Tabel
{
"_id": {
"$oid": "5cbac9172d962331401d0e48"
},
"appInstallCount": {
"$numberInt": "6"
},
"status": {
"$numberInt": "1"
},
"appName": "PC Access Log",
"appInfo": "You can view users who access your PC",
"appImageUrl": "assets/images/app/userlog-app-thismypc.png",
"userID": "5c3d6a25227a1d01eba0afc9",
"version": "1",
"released_date": {
"$date": {
"$numberLong": "1555745047247"
}
},
"lastUpdate_date": {
"$date": {
"$numberLong": "1555745047247"
}
},
"__v": {
"$numberInt": "0"
}
}{
"_id": {
"$oid": "5cbd300316e4651c78167478"
},
"appInstallCount": {
"$numberInt": "0"
},
"status": {
"$numberInt": "1"
},
"appName": "PC Access Log TEST",
"appInfo": "You can view users who access your PC",
"appImageUrl": "assets/images/app/userlog-app-thismypc.png",
"userID": "5c3d6a25227a1d01eba0afc9",
"version": "1",
"released_date": {
"$date": {
"$numberLong": "1555745047247"
}
},
"lastUpdate_date": {
"$date": {
"$numberLong": "1555745047247"
}
},
"__v": {
"$numberInt": "0"
}
}
and UserAndApps Tabel
{
"_id": {
"$oid": "5cbd327294877a70b510c8b6"
},
"status": {
"$numberInt": "1"
},
"userID": {
"$oid": "5cbd2d3e0afcb16efa795563"
},
"appID": {
"$oid": "5cbac9172d962331401d0e48"
},
"date": {
"$date": {
"$numberLong": "1555903090765"
}
},
"__v": {
"$numberInt": "0"
}
}{
"_id": {
"$oid": "5cbd327394877a70b510c8b7"
},
"status": {
"$numberInt": "1"
},
"userID": {
"$oid": "5cbd2d3e0afcb16efa795563"
},
"appID": {
"$oid": "5cbd300316e4651c78167478"
},
"date": {
"$date": {
"$numberLong": "1555903091265"
}
},
"__v": {
"$numberInt": "0"
}
}{
"_id": {
"$oid": "5cbd329a94877a70b510c8b9"
},
"status": {
"$numberInt": "1"
},
"userID": {
"$oid": "5c3d6a25227a1d01eba0afc9"
},
"appID": {
"$oid": "5cbac9172d962331401d0e48"
},
"date": {
"$date": {
"$numberLong": "1555903130918"
}
},
"__v": {
"$numberInt": "0"
}
}{
"_id": {
"$oid": "5cbd329b94877a70b510c8ba"
},
"status": {
"$numberInt": "1"
},
"userID": {
"$oid": "5c3d6a25227a1d01eba0afc9"
},
"appID": {
"$oid": "5cbd300316e4651c78167478"
},
"date": {
"$date": {
"$numberLong": "1555903131796"
}
},
"__v": {
"$numberInt": "0"
}
}
I use this code to join above two tabels
[
{
'$lookup': {
'from': 'userandapps',
'localField': '_id',
'foreignField': 'appID',
'as': 'appData'
}
}, {
'$unwind': {
'path': '$appData',
'preserveNullAndEmptyArrays': true
}
}, {
'$match': {
'appData.userID': new ObjectId('5cbd2d3e0afcb16efa795563')
}
}
]
The issue is it only returns that fill appData array, but I need that appData array to fill and empty both stages like in MYSQL LEFT JOIN. if 'appData.userID': new ObjectId('5cbd2d3e0afcb16efa795563')
not belong one of document. it also returns with an empty appData array. I tried many ways but I did not get any way to work this out. can someone help me with this? Big Help.
I try With this code and it returns empty without any data
[{
$lookup: {
from: 'userandapps',
localField: '_id',
foreignField: 'appID',
as: 'appData'
}
}, {
$unwind: {
path: "$appData",
preserveNullAndEmptyArrays: true
}
}, {
$match: {
"$or": [{
'appData.userID': ObjectId('5cbd2d3e0afcb16efa795563')
}, {
'appData': null
}]
}
}]