Menggunakan .aggregate()
metode dan $setUnion
operator.
db.collection.aggregate([
{ "$project": {
"attribute3": { "$setUnion": [ "$attribute1", "$attribute2" ] }
}}
])
Yang menghasilkan:
{
"_id" : ObjectId("52f0795a58c5061aa34d436a"),
"attribute3" : [8, 4, 2, 6, 3, 7, 1]
}