Created
April 13, 2011 21:43
-
-
Save tylerstalder/918492 to your computer and use it in GitHub Desktop.
Simple script to load a json file into couchdb
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
var fs = require('fs'), | |
sys = require('sys'), | |
http = require('http'); | |
var fileName = process.argv[2]; | |
var database = process.argv[3]; | |
var dataFeed = fs.readFileSync(fileName, encoding='utf8'); | |
var requestData = JSON.parse(dataFeed); | |
var local = http.createClient(80, 'open311.couchone.com'); | |
var requestCount = requestData.requests.length; | |
sys.puts("Importing " + requestCount + " records into http://open311.couchone.com/" + database + " from " + fileName); | |
for (var i = 0; i < requestCount; i++) { | |
var request = local.request('POST', '/' + database + '/', {'host': 'open311.couchone.com','Content-Type':'application/json'}); | |
request.write(JSON.stringify(requestData.requests[i]), encoding='utf8'); | |
request.end(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment