導(dǎo)入數(shù)據(jù)
from pymongo import MongoClient
host = 'localhost'
port = 27017
#連接MongoDB
client =MongoClient(host,port)
db = client['test']#新建test這個(gè)數(shù)據(jù)庫
sheet = db ['sheet']#新建sheet這個(gè)表
for i in range(1001):
print(i)
#插入數(shù)據(jù)
sheet.insert_one(
{
'name':'name'+ str(i),
'age':i
}
)
MongoDB導(dǎo)出
按住shift+右鍵在此處打開命令行
mongo
命令行
mongo
>show dbs
local 0.000GB
> use local
switched to db local
>show collections
startup_log
>db.startup_log.find()
得到里面內(nèi)容
mogoexport
json格式
mongoexport -d local -c startup_log -o startup_log.json
d data
c collection
o output
需要用管理員權(quán)限的命令行
csv格式 可以用excel打開
mongoexport -d local -c startup_log --csv -f hostname,startTime -o startup_log.csv
-f 指定列表
MongoDB數(shù)據(jù)導(dǎo)入
mongo
>db.createCollection('log')#創(chuàng)建Log文件夾
>show collections
log
sheet
>db.log.find()
mongoimport
json格式
mongoimport -d local -c log --file startup_log.json
csv格式
mongoimport -d local -c log --type csv --headerline --file startup_log.csv
headerline忽略第一行表頭 直接導(dǎo)入數(shù)據(jù)
startup_log.csv
stratup_log.csv