Есть коллекция:
{
"_id" : ObjectId("5338ec2a5b5b71242a1c911c"),
"people" : [
{
"name" : "Vasya"
},
{
"age" : "30"
},
{
"weight" : "80"
}
],
"animals" : [
{
"dog" : "Sharick"
},
{
"cat" : "Barsik"
},
{
"bird" : "parrot"
}
]
},
{
"_id" : ObjectId("5338ec7f5b5b71242a1c911d"),
"people" : [
{
"name" : "Max"
},
{
"age" : "32"
},
{
"weight" : "78"
}
],
"animals" : [
{
"dog" : "Borbos"
},
{
"cat" : "Murka"
},
{
"bird" : "Eagle"
}
]
}
Запрос:
db.tmp.aggregate({$project:{"union":{$setUnion:["$people","$animals"]}}})
и результат:
{
"result" : [
{
"_id" : ObjectId("5338ec2a5b5b71242a1c911c"),
"union" : [
{
"bird" : "parrot"
},
{
"name" : "Vasya"
},
{
"age" : "30"
},
{
"weight" : "80"
},
{
"dog" : "Sharick"
},
{
"cat" : "Barsik"
}
]
},
{
"_id" : ObjectId("5338ec7f5b5b71242a1c911d"),
"union" : [
{
"name" : "Max"
},
{
"age" : "32"
},
{
"weight" : "78"
},
{
"bird" : "Eagle"
},
{
"dog" : "Borbos"
},
{
"cat" : "Murka"
}
]
}
],
"ok" : 1
}
Как сделать так, чтобы поля каждой записи массива result выводились в одном и том же порядке, а не вразнобой?