Skip to content

Instantly share code, notes, and snippets.

@zubairalam
Last active August 29, 2015 14:16
Show Gist options
  • Save zubairalam/a8a364d8c27bd732d05c to your computer and use it in GitHub Desktop.
Save zubairalam/a8a364d8c27bd732d05c to your computer and use it in GitHub Desktop.
// Desired unique index:
// db.categories.ensureIndex({ category_url: 1, category_page_url: 1 }, { unique: true})
db.categories.aggregate([
{ $group: {
_id: { category_url: "$category_url", category_page_url: "$category_page_url" },
uniqueIds: { $addToSet: "$_id" },
count: { $sum: 1 }
}},
{ $match: {
count: { $gt: 1 }
}}
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment