I have two collections on which i have to do lookup query on ObjectId of both collections. Both local and foreign fields are of type ObjectId. I can convert one collection ObjectId to string with $toString method but how will i do the same with the other collection i want to join?
Json 1:
{
"_id": {
"$oid": "4efcggedwrg446"
},
"name": "Name1",
"phone": "12345678"
}
Json 2:
{
"_id": {
"$oid": "4efcggedwrg446"
},
"deviceId": "6552gggh732",
"deviceName": "samsung"
}
Query:
[{$addFields: {
"Id": { "$toString": "$_id" }
}}, {$lookup: {
from: 'json2',
localField: 'Id',
foreignField: '_id',
as: 'join'
}}]
Lookup query on _id of both json. How can i convert ObjectId of other collection ?
$oid
? its not ObjectId – Nikhil Savaliya