background
要讀一個多個json格式的文件,不想寫解析器(懶,就略微學了一下mongodb讀文件
ref
https://docs.mongodb.com/manual/
(mongoldb manual)
http://mac.softpedia.com/get/Developer-Tools/MongoBooster.shtml#download (mongobooster- a graphical user interface for connecting to MongoDB servers and managing databases)
http://api.mongodb.com/python/current/tutorial.html
(pymongo-a Python distribution containing tools for working with MongoDB)
評測
sudo mongod
然后打開mongobooster,connect之后把json文件import進去
也可以用mongo shell,一些命令
show dbs
use <db>
mongoimport --host=127.0.0.1 --db test --collection restaurants --drop --file <filename>
show collections
利用pymongo操作mongodb的一些常用代碼
import pymongo
from pymongo import MongoClient
client = MongoClient('mongodb://127.0.0.1:27017/')
db = client.<db>
line = db.<collection>
for l in line:
for key in l:
if key==x:
l[key]=y