您的位置:首页 > 数据库 > Mongodb

MongoDB 学习笔记

2017-10-24 00:00 363 查看
摘要: 第二课-初体验

import pymongo

client = pymongo.MongoClient('localhost',27017)          #利用pymongo的mongoclinet 方法构造clinet
xiaoshuo = client['xiaoshuo']                            #利用clinet对象建立xiaoshuo表
sheet_1 = xiaoshuo['sheet_1']                            #建立表内的不同sheet

#读取小说信息
path = '/Users/JiaWeiFang/Downloads/117524.txt'
with open (path,'r') as f:
lines = f.readlines()
for index,line in enumerate(lines):
data = {
'index':index,
'line':line,
'words':len(line.split())
}
sheet_1.insert_one(data)  #利用sheet_1.insert_one()方法一个一个插入sheet表 这个动作不要重复做

#'$lt' '$lte' '$gt' '$gte' '$ne'
#for item in sheet_1.find({'words':{'$lt':10}}): #通过利用sheet.find方法 读取想要的东西 在函数内使用字典删选
#print(item)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  PyMongo MongoDB