Skip to content

Instantly share code, notes, and snippets.

@chadwilcomb
Created May 4, 2017 18:55
Show Gist options
  • Save chadwilcomb/03c332864a0d4fdf85190d738eb59f5e to your computer and use it in GitHub Desktop.
Save chadwilcomb/03c332864a0d4fdf85190d738eb59f5e to your computer and use it in GitHub Desktop.
Script to run through a Mongo collection with some malformed geometries and flag and unset the geometries
for (i = 0; i < 139; i++) {
db.basemap_clean.ensureIndex({ geometry: "2dsphere" })
db.basemap_features
.find({ clean: { $exists: 0 } }, { "geometry": 1 })
.limit(500000)
.forEach(function (feature) {
db.basemap_clean.insert(feature);
});
db.basemap_clean
.find()
.forEach(function (clean) {
db.basemap_features.update({ _id: clean._id }, { $set: { clean: 1 } })
});
db.basemap_clean.drop();
}
db.basemap_features.find({ clean: { $exists: 0 }}).forEach(function (doc) {
db.basemap_features.update(
{ _id: doc._id },
{ $set: { malgeo: doc.geometry }, $unset: { geometry: 1 } }
);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment