1

Lets say that i have the following objects in my mongodb-compass-database:

{
   _id: ObjectID("randomString"),
   Name: "Test1",
   OtherAttribute: 187
},
{
   _id: ObjectID("otherRandomString"),
   Name: "Test2",
   OtherAttribute: 1337
},
{
   _id: ObjectID("otherRandomString2"),
   Name: "Test1",
   OtherAttribute: 23
}

How can I return the "Name"-value if it exist more than one time? In the example I want to receive "Test1" or the whole object, doesnt matter.

I just need to see if there are any duplicates.

I need to use the MongoDB Compass Find-Input: enter image description here

Is this possible?

elFusion
  • 57
  • 6
  • 1
    Does this answer your question? [Find duplicate records in MongoDB](https://stackoverflow.com/questions/26984799/find-duplicate-records-in-mongodb) you need to write aggregation query look at the accepted answer. – turivishal Nov 27 '20 at 07:30
  • @turivishal Thank you for your replay. I already found this solution but im absolutly new to mongodb-querys and I'm currently not able to write such a query, that's why I'm asking here for help. I know SQL-Querys but I don't understand mongo-querys yet. So if you know how this works excatly I would love to see a solution form you which fits my sample collection above.. – elFusion Nov 27 '20 at 07:38
  • 1
    This is the exact solution you just need to replace your keys in that answer's query, you really want to me to do copy and paste that query for your? there are many questions related your question in Stack overflow, just google it. you will find everything. and i don't want to increase duplicate questions and answers. – turivishal Nov 27 '20 at 07:43

0 Answers0