Created
October 23, 2009 17:23
-
-
Save cwsaylor/217060 to your computer and use it in GitHub Desktop.
Demonstrates how easy it is to save json data directly to MongoDB
This file contains hidden or 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
require 'json' | |
require 'open-uri' | |
require 'mongo' | |
include Mongo | |
url = 'http://search.twitter.com/trends.json' | |
buffer = open(url, 'UserAgent' => 'Ruby-Wget').read | |
result = JSON.parse(buffer) | |
c = Connection.new('localhost') | |
db = c.db('twitter') | |
trends = db.collection('trends') | |
trends.insert result | |
trends.find_one |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment