hotdeal:
{ "property" : "ATL-D406" }
translation:
{ "property" : "ATL-D406", "language" : "gb", "txt": [{"aaa":"hi", "bbb":"bye"}] }
{ "property" : "ATL-D406", "language" : "ru", "txt": [{"aaa":"priviet", "bbb":"baka"}] }
{ "property" : "ATL-D406", "language" : "cn", "txt": [{"aaa":"??", "bbb":"??"}] }
Current result:
{ "property":"ATL-D406", "language":[ "gb", "ru", "cn" ] }
What I would like:
{ "property":"ATL-D406", "language":"gb", "aaa":"hi", "bbb":"bye" }
I cannot understand why my $elemMatch is not working, shouldn't it isolate that particular element in the result from "translation"?
Also once I got it to only take the "gb" language, how do I project "aaa" and "bbb" without them being inside an array? I tried $resolve but then I get no data at all. Can you $resolve an array in an array? ($resolve "txt")?
db.hotdeal.aggregate([
{ '$match': {} },
{ '$lookup': {
from: 'translation',
localField: 'property',
foreignField: 'property',
as: 'translations'
} },
{ '$match':
{ 'translations':
{ '$elemMatch': { 'language': 'gb' } }
}
},
{ '$project': {
_id: 0,
property: 1,
language: '$translations.language'
}}
])