Skip to content

Instantly share code, notes, and snippets.

@gousiosg
Created October 9, 2015 08:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gousiosg/26177bb7cd1ab8a76eeb to your computer and use it in GitHub Desktop.
Save gousiosg/26177bb7cd1ab8a76eeb to your computer and use it in GitHub Desktop.
Convert JSON to BSON for importing into MongoDB
#!/usr/bin/env ruby
require 'json'
require 'bson' # Requires bson version > 3
json = JSON.parse(File.open(ARGV[0]).read)
w = File.open("#{ARGV[0]}.bson",'w')
json.each do |j|
w.write(j.to_bson)
end
w.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment