How to count the documents duplicated in mongodb?

I tried to search how to count the documents duplicated in mongodb and i got this function, it return the documents duplicated.

db.job_crawler_models_jobs_crawlings.aggregate(
    { $group: { 
        _id: { field1: "$field1", field2: "$field2" },
        count: { $sum:  1 }
    }},
    { $match: {
        count: { $gt : 1 }
    }}
)

But i want to get the number of documents duplicated. How can i do that?

Answers


You could try adding another $group in the pipeline. Not sure this is exactly what you are looking for though.

db.job_crawler_models_jobs_crawlings.aggregate(
{ $group: { 
    _id: { field1: "$field1", field2: "$field2" },
    count: { $sum:  1 }
}},
{ $match: {
    count: { $gt : 1 }
}},
{ $group: { _id: null, duplicatedCounts: { $sum:1 } } }
)

Need Your Help

Asp.net MVC action and view issue

asp.net-mvc-3 pagination

I am stuck in a weird situation. I have a controller action which is passed a category string. Then the action method matches the string in the database and collects the sub categories and products...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.