本地获取服务器上的mongo数据库中的数据

2018-09-11  本文已影响0人  暖遇

本地获取服务器上面的mongo的数据,下面的代码写的很清晰,如下:

encoding:utf-8

import pymongo

连接mongo

client=pymongo.MongoClient('139.196.100.176',27017)

连接到哪一个数据库

dbdb =client['weibo_test']

到哪一个集合

phone153 = dbdb['153']

查询出多少条记录,这里的find你也可以加条件

print(phone153.find().count())

for i in phone131.find():

f.write(i['phone'] + '\n')

# print(i['phone'])

将数据写到txt的文件中

with open('F:\工作文件\DataTgNew号码\weibo-9-10\data_weibo__153.txt','w')as f:

for i in phone153.find():

f.write(i['phone']+'\n')

上一篇 下一篇

猜你喜欢

热点阅读