import pymongo
client=pymongo.MongoClient('localhost',27017) #localhost 指的是本地登渣,激活本地mongo客戶端荞胡,創(chuàng)建本地MongoDB
walden=client['walden'] #左邊是python對(duì)象,中括號(hào)中的是數(shù)據(jù)庫(kù)中的名稱,建議對(duì)象和名稱一致? 類似創(chuàng)建 excel表
sheet_lines=walden['sheet_lines'] ?#類似于excel表中的第一個(gè)表單
# path = r'F:\5-學(xué)習(xí)\python學(xué)習(xí)\20170111\walden.txt'
#
# with open(path, 'r') as f:
#? ? lines = f.readlines()
#? ? for index,words in enumerate(lines):
#? ? ? ? data = {
#? ? ? ? ? ? 'index':index,
#? ? ? ? ? ? 'line':words,
#? ? ? ? ? ? 'word':len(words.split())
#? ? ? ? }
#? ? ? ? sheet_lines.insert_one(data)
# $lt/$lte/$gt/$gte/$ne模捂,依次等價(jià)于/>=/!=。(l表示less g表示greater e表示equal n表示not? )
foriteminsheet_lines.find({'word':{'$lt':5}}):#查找小于5個(gè)單詞的表項(xiàng)
print(item)
知識(shí)小結(jié):
1、數(shù)據(jù)庫(kù)的建立和表單的創(chuàng)建
2厦瓢、數(shù)據(jù)庫(kù)中數(shù)據(jù)插入提揍、查詢,按照條件查詢煮仇,后續(xù)還需要學(xué)習(xí)數(shù)據(jù)庫(kù)更多的操作方法