美文网首页
本地获取服务器上的mongo数据库中的数据

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

作者: 暖遇 | 来源:发表于2018-09-11 14:05 被阅读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')

相关文章

网友评论

      本文标题:本地获取服务器上的mongo数据库中的数据

      本文链接:https://www.haomeiwen.com/subject/ezmcgftx.html