Monday, February 17, 2014

Load all json files from folder to MondoDB

Here is one way to quickly load number of json files to DB (MongoDB) for quick data mining:

#!/usr/bin/bash

ls -1 *.json | sed 's/.json$//' | while read col; do
   ./mongoimport -h mongodb.mycompany.com --db mytests --collection news --file $col.json --jsonArray
done


SQL to investigate data, "news" is collection, 'Headline' is filed in json:
db.news.find({Headline: {$regex: " for period end .*"}},  {Headline:1, _id:0})

Links:
http://docs.mongodb.org/manual/core/import-export/

No comments:

Post a Comment