本文整理汇总了Python中pymongo.connection.Connection.ensure_index方法的典型用法代码示例。如果您正苦于以下问题:Python Connection.ensure_index方法的具体用法?Python Connection.ensure_index怎么用?Python Connection.ensure_index使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymongo.connection.Connection
的用法示例。
在下文中一共展示了Connection.ensure_index方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MongoHandler
# 需要导入模块: from pymongo.connection import Connection [as 别名]
# 或者: from pymongo.connection.Connection import ensure_index [as 别名]
class MongoHandler(logging.Handler):
""" Custom log handler
Logs all messages to a mongo collection. This handler is
designed to be used with the standard python logging mechanism.
"""
@classmethod
def to(cls, db, collection, host='localhost', port=None, level=logging.NOTSET):
""" Create a handler for a given """
return cls(Connection(host, port)[db][collection], level)
def __init__(self, collection, db='mongolog', host='localhost', port=None, level=logging.NOTSET):
""" Init log handler and store the collection handle """
logging.Handler.__init__(self, level)
if (type(collection) == str):
self.collection = Connection(host, port)[db][collection]
else:
self.collection = collection
self.collection.ensure_index([("time", -1)])
self.collection.ensure_index([("levelname", 1), ("time", -1)])
self.formatter = MongoFormatter()
def emit(self, record):
""" Store the record to the collection. Async insert """
try:
self.collection.save(self.format(record))
except InvalidDocument, e:
logging.error("Unable to save log record: %s", e.message, exc_info=True)
示例2: Connection
# 需要导入模块: from pymongo.connection import Connection [as 别名]
# 或者: from pymongo.connection.Connection import ensure_index [as 别名]
# -*- coding: utf-8 -*-
import sys
import time
import sage.all
from sage.all import gap
from pymongo.connection import Connection
groups = Connection(port=dbport).transitivegroups.groups
groups = Connection(port=dbport).transitivegroups.groups
groups.ensure_index('n')
groups.ensure_index('t')
# Import information in the a database of transitive groups
def base_label(n, t):
return str(n) + "T" + str(t)
def lookup_or_create(label):
item = None # fields.find_one({'label': label})
if item is None:
return {'label': label}
else:
return item
def tf(val):
if val: