Skip to content

Instantly share code, notes, and snippets.

@valter-jnr
Created September 9, 2020 21:57
Show Gist options
  • Save valter-jnr/b12df7dd12979602981e0f53c30bed68 to your computer and use it in GitHub Desktop.
Save valter-jnr/b12df7dd12979602981e0f53c30bed68 to your computer and use it in GitHub Desktop.
db.getCollection('places').distinct("address.complete").forEach(fieldValue => {
var count = db.getCollection('places').find({"address.complete": fieldValue }).count();
if (count > 1) {
db.getCollection('places').find({"address.complete": fieldValue }).forEach(doc => {
if (count > 1) {
db.getCollection('places').remove({ _id: doc._id });
count--;
}
});}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment