Skip to content

Instantly share code, notes, and snippets.

@dblock
Created February 2, 2013 20:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dblock/4699070 to your computer and use it in GitHub Desktop.
Save dblock/4699070 to your computer and use it in GitHub Desktop.
Find corrupted MongoDB embedded items inside multiple collections. Code from @macreery.
summary_totals = {}
summary_totals.default = 0
count = 0
{
Collection => :items,
Artwork => :images
}.each do |coll, orderable_subcoll|
coll.all.each do |item|
$stdout.write "." if count % 1000 == 0
count += 1
if (item.collection.find(_id: item._id).first[orderable_subcoll.to_s] || []).any? { |doc_subitem| (doc_subitem || {})['_id'].nil? }
puts "\n#{coll}:#{item._id}\n"
summary_totals[coll] += 1
end
end
end
puts "\n\n === SUMMARY ==="
summary_totals.each do |k, v|
puts "#{k}: #{v} bad documents"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment