#!/usr/bin/env python
#coding:utf-8
from pymongo import MongoClient
from pymongo import MongoReplicaSetClient
if __name__ == '__main__':
mongodbHostPort1 = 'mongodb://%s:%s@%s:27017,%s:27017,%s:27017/%s' %
(account, pwd, ip1, ip2, ip3, dbname)
# mongodbHostPort2 = 'mongodb://%s:%s@%s:%s/%s' % (account, pwd, ip, port, dbname)
mongodbClient = MongoReplicaSetClient(mongodbHostPort1)
# mongodbClient = MongoClient(mongodbHostPort2)
mongodbDb = '%s' dbname
collection_useraction = mongodbClient[mongodbDb]
collection_useraction.dbname.delete_many({'date': dttime})
collection_useraction.dbname.insert_one({'date':dttime,
'platform':item[0], 'pv':item[1], 'uv':item[2]})
more:
http://api.mongodb.com/python/current/api/pymongo/collection.html