我有问题。在我的mongoDB数据库中,有多个数据,每个数据都有一个数组字段。在此数组字段中有大量重复数据。因此,我想从此数组中删除重复数据,并仅保留重复数据中的一个数据。所以我确实想通过mongo shell删除重复项。我的数据结构如下:
{
"_id" : ObjectId("5b7a3aa578b8d7a3e7d9dc09"),
"a" : [
{
"loc" : "111",
"name" : "B"
},
{
"loc" : "111",
"name" : "B"
},
{
"loc" : "111",
"name" : "A"
},
{
"loc" : "111",
"name" : "A"
}
{
"loc" : "222",
"name" : "B"
},
{
"loc" : "222",
"name" : "A"
}
]
}
{
"_id" : ObjectId("5b7a67f78e063bbbde7135c6"),
"a" : [
{
"loc" : "111",
"name" : "B"
},
{
"loc" : "111",
"name" : "B"
}
]
}
我的期望如下所示:
{
"_id" : ObjectId("5b7a3aa578b8d7a3e7d9dc09"),
"a" : [
{
"loc" : "111",
"name" : "B"
},
{
"loc" : "222",
"name" : "A"
}
]
}
{
"_id" : ObjectId("5b7a67f78e063bbbde7135c6"),
"a" : [
{
"loc" : "111",
"name" : "B"
}
]
}
我正在使用MongoDB 3.6。因此,请帮助我,并推荐一个用于从阵列中删除所有重复项的函数,并仅保留一个
谢谢