Created
June 1, 2010 16:42
-
-
Save lstoll/421137 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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