查找具有相同值的重复项 MongoDB
我有一个数据集,我想在多行中找到具有相同值的重复项。例如,我有一个包含12行的数据集,除了_id和标题值之外,底部2行具有相似的值。我该如何查找这些结果?好像我还不知道这些是重复的。 我的收藏是“销售”
[
{
_id: "C12",
title: "blouse",
price: 15,
units_sold: 100,
retail_price: 30,
ad_boost: 1,
rate_count: 34,
rating: 4
},
{
_id: "C10",
title: "loose floral blouse",
price: 15,
units_sold: 100,
retail_price: 30,
ad_boost: 1,
rate_count: 34,
rating: 4
}
]
I have a data set that I want to find the duplicates with the same values in multiple rows. For instance I have a data set that contains 12 different rows and I know the bottom 2 rows have similar values besides the _id and title values. How do I query to find these results? As if i dont already know these are duplicates.
My collection is 'sales'
[
{
_id: "C12",
title: "blouse",
price: 15,
units_sold: 100,
retail_price: 30,
ad_boost: 1,
rate_count: 34,
rating: 4
},
{
_id: "C10",
title: "loose floral blouse",
price: 15,
units_sold: 100,
retail_price: 30,
ad_boost: 1,
rate_count: 34,
rating: 4
}
]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需
$ group
,您将标识为重复检查密钥的所有字段。您可以$ push
_id
进入数组,以供以后获取/处理。这是 mongo Playground 供您参考。
Simply
$group
by all the fields that you identify as duplicate check key. You can$push
the_id
into an array for later fetching/processing.Here is the Mongo playground for your reference.