首页 > 数据库技术 > 详细

python连接mongodb

时间:2018-10-12 12:42:43      阅读:151      评论:0      收藏:0      [点我收藏+]

import random
import time
from datetime import *
import pymongo

client = pymongo.MongoClient(‘***.**.**.**‘, *****, username=‘*****‘, password=‘******‘)

db_name = ‘feeds‘
db = client[db_name]


collection_set02 = db[‘feedsDO‘]

collection_set03 = db[‘relationDO‘]

count = 0
result1 = []
result2 = []
result3 = []
try:

for i in range(10003110000, 20000000000): # 200 - 299

subscriber = 100000000 + i
publisher = 600000000 + i
type = 555
msg = "MongoDB是一个介于关系数据库和非关系数据库之间的产品,是非关系数据库当中功能最丰富,最像关系数据库的。它支持的数据结构非常松散,是类似json的bson格式,因此可以存储比较复杂的数据类型。Mongo最大的特点是它支持的查询语言非常强大,其语法有点类似于面向对象的查询语言,几乎可以实现类似关系数据库单表查询的绝大部分功能,而且还支持对数据建立索引"
detailType = "888"
createTime = 1538988966588


data_01 = {"createTime":createTime,"detailType":detailType,"msg":msg,"publisher":publisher,"type":type}
data_02 = {"createTime":createTime,"detailType":detailType,"msg":msg,"publisher":publisher,"subscriber":subscriber,"type":type}
data_03 = {"publisher":publisher,"subscriber":subscriber,"type":type}

result1.append(data_01)
result2.append(data_02)
result3.append(data_03)

count += 1
if(count == 10000):
collection_set02.insert_many(result1)
collection_set02.insert_many(result2)
collection_set03.insert_many(result3)

print(i)
result1 = []
result2 = []
result3 = []
count = 0
except pymongo.errors.DuplicateKeyError:
print(‘record exists‘)
except Exception as e:
print(e)

 

python连接mongodb

原文:https://www.cnblogs.com/perTest/p/9777106.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!