本文整理匯總了Python中pymongo.Connection方法的典型用法代碼示例。如果您正苦於以下問題:Python pymongo.Connection方法的具體用法?Python pymongo.Connection怎麽用?Python pymongo.Connection使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pymongo
的用法示例。
在下文中一共展示了pymongo.Connection方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: depiler
# 需要導入模塊: import pymongo [as 別名]
# 或者: from pymongo import Connection [as 別名]
def depiler(pile, pile_deleted, pile_catchup, pile_medias, mongoconf, locale, exit_event, debug=False):
db = MongoClient(mongoconf['host'], mongoconf['port'])[mongoconf['db']]
coll = db['tweets']
while not exit_event.is_set() or not pile.empty() or not pile_deleted.empty():
while not pile_deleted.empty():
todelete = pile_deleted.get()
coll.update({'_id': todelete}, {'$set': {'deleted': True}}, upsert=True)
todo = []
while not pile.empty():
todo.append(pile.get())
stored = 0
for t in prepare_tweets(todo, locale):
if pile_medias and t["medias"]:
pile_medias.put(t)
if pile_catchup and t["in_reply_to_status_id_str"]:
if not coll.find_one({"_id": t["in_reply_to_status_id_str"]}):
pile_catchup.put(t["in_reply_to_status_id_str"])
tid = coll.update({'_id': t['_id']}, {'$set': t}, upsert=True)
stored += 1
if debug and stored:
log("DEBUG", "Saved %s tweets in MongoDB" % stored)
breakable_sleep(2, exit_event)
log("INFO", "FINISHED depiler")
示例2: after_login
# 需要導入模塊: import pymongo [as 別名]
# 或者: from pymongo import Connection [as 別名]
def after_login(self, response):
connection = pymongo.Connection("localhost", 27017)
self.db = connection["zhihu"]
self.zh_user_col = self.db["zh_user"]
for key in ["高新科技", "互聯網", "電子商務", "電子遊戲", "計算機軟件", "計算機硬件"]:
users = self.zh_user_col.find({"industry": key})
# print users.count()
for user in users:
# questions
num = int(user['ask_num']) if "ask_num" in user.keys() else 0
page_num = num / 20
page_num += 1 if num % 20 else 0
for i in xrange(page_num):
url = host + "/people/" + user["username"] + '/asks?page=%d' % (i + 1)
yield Request(url, callback=self.parse_ask)
示例3: after_login
# 需要導入模塊: import pymongo [as 別名]
# 或者: from pymongo import Connection [as 別名]
def after_login(self, response):
connection = pymongo.Connection("localhost", 27017)
self.db = connection["zhihu"]
self.zh_user_col = self.db["zh_user"]
for key in ["高新科技", "互聯網", "電子商務", "電子遊戲", "計算機軟件", "計算機硬件"]:
users = self.zh_user_col.find({"industry": key})
# print users.count()
for user in users:
# answers
num = int(user['answer_num']) if "answer_num" in user.keys() else 0
page_num = num / 20
page_num += 1 if num % 20 else 0
for i in xrange(page_num):
yield Request(host + "/people/" + user["username"] + '/answers?page=%d' % (i + 1),
callback=self.parse_ans)
示例4: get_connection
# 需要導入模塊: import pymongo [as 別名]
# 或者: from pymongo import Connection [as 別名]
def get_connection():
global _connection
if not _connection:
_connection = Connection(
host=getattr(settings, 'MONGODB_HOST', None),
port=getattr(settings, 'MONGODB_PORT', None)
)
username = getattr(settings, 'MONGODB_USERNAME', None)
password = getattr(settings, 'MONGODB_PASSWORD', None)
db = _connection[settings.MONGODB_DATABASE]
if username and password:
db.authenticate(username, password)
return db
return _connection[settings.MONGODB_DATABASE]
示例5: __init__
# 需要導入模塊: import pymongo [as 別名]
# 或者: from pymongo import Connection [as 別名]
def __init__(self, **kwargs):
super(MongoDB, self).__init__(**kwargs)
if self._connection is None:
self._connection = Connection(*self.connection_args, **self.connection_kwargs)
if not self.database:
self.database = self.session
self._db = self._connection[self.database]
self._records = self._db['task_records']
self._records.ensure_index('msg_id', unique=True)
self._records.ensure_index('submitted') # for sorting history
# for rec in self._records.find
示例6: __init__
# 需要導入模塊: import pymongo [as 別名]
# 或者: from pymongo import Connection [as 別名]
def __init__(self, host = db_config['DB_HOST'],
port = db_config['DB_PORT'],
user = db_config['DB_USER'],
passwd = db_config['DB_PSW'],
db = db_config['DB_NAME'],
charset = db_config['DB_CHARSET']):
self.connection = pymongo.Connection(host, port)
self.db = self.connection[db]
self.db.authenticate(user, passwd)
示例7: setUp
# 需要導入模塊: import pymongo [as 別名]
# 或者: from pymongo import Connection [as 別名]
def setUp(self):
self.client = pymongo.Connection(os.environ.get("TEST_MONGODB"))
self.db = self.client.test_queue
self.collection = self.db.locks
示例8: __init__
# 需要導入模塊: import pymongo [as 別名]
# 或者: from pymongo import Connection [as 別名]
def __init__(self):
self.server = settings['MONGODB_SERVER']
self.port = settings['MONGODB_PORT']
self.db = settings['MONGODB_DB']
self.col = settings['MONGODB_COLLECTION']
connection = pymongo.Connection(self.server, self.port)
db = connection[self.db]
self.collection = db[self.col]
示例9: __init__
# 需要導入模塊: import pymongo [as 別名]
# 或者: from pymongo import Connection [as 別名]
def __init__(self):
conn = pymongo.Connection(
settings['MONGO_CONF']['host'],
settings['MONGO_CONF']['port']
)
db = conn[settings['MONGO_CONF']['db']]
self.news_collection = db[settings['MONGO_CONF']['collection']]
示例10: nosql
# 需要導入模塊: import pymongo [as 別名]
# 或者: from pymongo import Connection [as 別名]
def nosql():
import pymongo
import json
conn = pymongo.Connection('127.0.0.1', port=27017)
df = ts.get_tick_data('600848',date='2014-12-22')
print(df.to_json(orient='records'))
conn.db.tickdata.insert(json.loads(df.to_json(orient='records')))
# print conn.db.tickdata.find()
示例11: connect_to_db_collection
# 需要導入模塊: import pymongo [as 別名]
# 或者: from pymongo import Connection [as 別名]
def connect_to_db_collection(db_name, collection_name):
'''
Retrieve collection from given database name and collection name
'''
connection = pymongo.Connection('localhost', 27017)
db = connection[db_name]
collection = db[collection_name]
return collection
示例12: connect_to_db_collection
# 需要導入模塊: import pymongo [as 別名]
# 或者: from pymongo import Connection [as 別名]
def connect_to_db_collection(db_name, collection_name):
'''
Return collection of a given database name and collection name
'''
connection = pymongo.Connection('localhost', 27017)
db = connection[db_name]
collection = db[collection_name]
return collection
示例13: connect_to_db_collection
# 需要導入模塊: import pymongo [as 別名]
# 或者: from pymongo import Connection [as 別名]
def connect_to_db_collection(db, collection):
db_name = db
collection_name = collection
# Get database connection and collections
connection = pymongo.Connection('localhost', 27017)
db = connection[db_name]
tracking = db[collection_name]
tracking_imported = db[collection_name + "_imported"]
return tracking, tracking_imported
示例14: connectMongo
# 需要導入模塊: import pymongo [as 別名]
# 或者: from pymongo import Connection [as 別名]
def connectMongo(self):
"""連接MongoDB數據庫"""
try:
self.__mongoConnection = Connection()
self.__mongoConnected = True
self.__mongoTickDB = self.__mongoConnection['TickDB']
self.writeLog(u'回測引擎連接MongoDB成功')
except ConnectionFailure:
self.writeLog(u'回測引擎連接MongoDB失敗')
#----------------------------------------------------------------------
示例15: __connectMongo
# 需要導入模塊: import pymongo [as 別名]
# 或者: from pymongo import Connection [as 別名]
def __connectMongo(self):
"""連接MongoDB數據庫"""
try:
self.__mongoConnection = Connection()
self.__mongoConnected = True
self.__mongoTickDB = self.__mongoConnection['TickDB']
self.writeLog(u'策略引擎連接MongoDB成功')
except ConnectionFailure:
self.writeLog(u'策略引擎連接MongoDB失敗')
#----------------------------------------------------------------------