I have collection
[{
"_id" : "5c9a69ef42c82b0197a2ffb8",
"key" : "a",
"language" : "en",
"version" : "0.1",
},
{
"_id" : "5c9a69ef42c82b0197a2ffb8",
"key" : "b",
"language" : "en",
"version" : "0.1",
},
{
"_id" : "5c9a69ef42c82b0197a2ffb8",
"key" : "b",
"language" : "en",
"version" : "0.2",
},
{
"_id" : "5c9a69ef42c82b0197a2ffb8",
"key" : "c",
"language" : "en",
"version" : "0.2",
}]
so I have 2 queries that getting version 0.1 and version 0.2, And I need to find the difference between them?
I need to get all of translation 0.2 that does not exist in translation 0.1.
Here is a solution to get all translations
key
that has a 0.2 version but not a 0.1 version.$sort
the translations by versions.$group
, I get all the versions for a givenkey
.$match
remove all the key that have a version 0.1$replaceRoot
keep only the last version for akey
try it here
If you remove the
$match
, you can also retrieve the last version available for each translation.try it here