Created
March 9, 2011 05:22
-
-
Save jharjono/861735 to your computer and use it in GitHub Desktop.
Dump JSON documents into MongoDB
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
#!/usr/bin/env ruby | |
# Dump JSON documents into MongoDB | |
require 'rubygems' | |
require 'mongo' | |
require 'json' | |
# Grab the dataset from a dump | |
filename = ARGV.first | |
docs = JSON.parse(File.open(filename).read) | |
# Get handle to MongoDB | |
db = Mongo::Connection.new("localhost", 27017).db("mydb") | |
collection = db.collection("my_collection") | |
# Insert each document | |
docs.each do |doc| | |
collection.insert(doc) | |
end | |
puts collection |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment