Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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