Skip to content

Instantly share code, notes, and snippets.

@lstoll
Created June 1, 2010 16:42
Show Gist options
  • Save lstoll/421137 to your computer and use it in GitHub Desktop.
Save lstoll/421137 to your computer and use it in GitHub Desktop.
## Converts ObjectIds to Strings in a mongodb json dump. Can use this to convert for use in mongoid
require 'json'
def convert_id(item)
if id = item['_id']['$oid']
item['_id'] = id
end
end
$stdin.each_line do |line|
json = JSON.parse(line)
convert_id(json)
old = json['old']
if old.kind_of? Array
json['old'].each do |o|
convert_id(o)
end
end
puts json.to_json
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment