Skip to content

Instantly share code, notes, and snippets.

@JaiHirsch
Created July 29, 2016 20:18
Show Gist options
  • Save JaiHirsch/0405329396906f4bbce452002b970405 to your computer and use it in GitHub Desktop.
Save JaiHirsch/0405329396906f4bbce452002b970405 to your computer and use it in GitHub Desktop.
db.value.aggregate([
{$project:{ time:1,values:[{c:"$c"},{v:"$v"}]} },
{
$project: {
time:1,
values2: {
$map: {
input: "$values",
as: "pair",
in: [{$ifNull:["$$pair.c","v-rep"]}, {$ifNull:["$$pair.v","c-rep"]}]
}
}
}
},
{
$project: {
time:1,
values3: {
$concatArrays: [{$arrayElemAt: ["$values2",0]}, {$arrayElemAt: ["$values2",1]}]
}
}
},
{
$project: {
time:1,
values4: {
$filter: {
input: "$values3",
as: "var",
cond: {$and : [
{$ne:["$$var","v-rep"]},
{$ne:["$$var","c-rep"]}
]},
}
}
}
},
{
$group: { _id:{"time":"$time"},
values5: {$push: "$values4"},
}
}
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment