2
我將根據X和Y刪除重複數據時它們是相同的值,因此在這種情況下(需要刪除在z = 3和Z = 4)
我使用
db.collection.aggregate([{"$sort":{ "_id": 1 }},{"$group":{"_id":"$x","doc":{"$first":"$$ROOT"}}},{"$replaceRoot":{"newRoot":"$doc"}},{"$out":"collection"}])
,但有一個關鍵的X
Json View
{
"_id" : ObjectId("59d9e7b4ad433ce84a235e93"),
"x" : NumberInt(1),
"y" : NumberInt(1),
"z" : NumberInt(1)
}
{
"_id" : ObjectId("59d9e7d0ad433ce84a235e95"),
"x" : NumberInt(1),
"z" : NumberInt(2),
"y" : NumberInt(2)
}
{
"_id" : ObjectId("59d9e7d2ad433ce84a235e97"),
"z" : NumberInt(3),
"x" : NumberInt(2),
"y" : NumberInt(3)
}
{
"_id" : ObjectId("59d9e7d4ad433ce84a235e99"),
"z" : NumberInt(4),
"x" : NumberInt(2),
"y" : NumberInt(3)
}
{
"_id" : ObjectId("59d9e7d7ad433ce84a235e9b"),
"x" : NumberInt(3),
"y" : NumberInt(4),
"z" : NumberInt(5)
}
使用
刪除重複的請出示從蒙戈樣本JSON文檔。 – Astro