当前位置: 首页>>代码示例>>Python>>正文


Python Connection.save方法代码示例

本文整理汇总了Python中pymongo.connection.Connection.save方法的典型用法代码示例。如果您正苦于以下问题:Python Connection.save方法的具体用法?Python Connection.save怎么用?Python Connection.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pymongo.connection.Connection的用法示例。


在下文中一共展示了Connection.save方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: MongoHandler

# 需要导入模块: from pymongo.connection import Connection [as 别名]
# 或者: from pymongo.connection.Connection import save [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)
开发者ID:baden,项目名称:mongodb-log,代码行数:32,代码来源:handlers.py

示例2: base_label

# 需要导入模块: from pymongo.connection import Connection [as 别名]
# 或者: from pymongo.connection.Connection import save [as 别名]
        'b7':b7,
        'ae2':ae2,
        'be2':be2,
        'ae3':ae3,
        'be3':be3,
        'ae5':ae5,
        'be5':be5,
        'ae7':ae7,
        'be7':be7,
        'coeffs':coeffs,
        'cond':cond
    }
    #index = 1
    #is_new = True
    #holdfield = ''
    #for field in fields.find({'degree': d,
    #                          'signature': data['signature'],
    #                          'disc_abs_key': dstr}):
    #    index += 1
    #    if field['coeffs'] == data['coeffs']:
    #        holdfield = field
    #        is_new = False
    #        break

    #if is_new:
    #print "new field"
    #label = base_label(d, sig[0], absD, index)
    #info = {'label': label}
    hgm.save(data)

开发者ID:MarkWatkins2014,项目名称:lmfdb,代码行数:31,代码来源:import_hgm.py

示例3: base_label

# 需要导入模块: from pymongo.connection import Connection [as 别名]
# 或者: from pymongo.connection.Connection import save [as 别名]
            'cyc': cyc,
            'ab': ab,
            'solv': solv,
            'prim': prim,
            'parity': gal[2],
            'order': gal[1],
            'name': gal[4],
            'auts': gal[3],
            'repns': gal[6],
            'resolve': gal[5],
            'subs': gal[7],
            'pretty': pretty
        }

        label = base_label(n, t)
        group = groups.find_one({'label': label})

        if group:
            print "old group"
            if 'pretty' in group:
                del data['pretty']
            group.update(data)
            print "entering %s" % group
            groups.save(group)
        else:
            print "new group"
            info = {'label': label}
            info.update(data)
            print "entering %s into database" % info
            groups.save(info)
开发者ID:CleryFabien,项目名称:lmfdb,代码行数:32,代码来源:import_galois-data.py

示例4: base_label

# 需要导入模块: from pymongo.connection import Connection [as 别名]
# 或者: from pymongo.connection.Connection import save [as 别名]
    data = {
        "degree": d,
        "signature": sig,
        "discriminant": D,
        "coefficients": coeffs,
        "class_number": h,
        "class_group": cyc,
        "galois_group": GG,
    }

    index = 1
    is_new = True
    for field in fields.find({"degree": d, "signature": sig, "discriminant": D}):
        index += 1
        if field["coefficients"] == coeffs:
            is_new = False
            break

    if is_new:
        print "new field"
        label = base_label(d, sig[0], absD, index)
        info = {"label": label}
        info.update(data)
        print "entering %s into database" % info
        fields.save(info)
    else:
        print "field already in database"
    if time.time() - t > 5:
        print "\t", label
        t = time.time()
开发者ID:swisherh,项目名称:swisherh-logo,代码行数:32,代码来源:import_jjnf_data.py

示例5: base_label

# 需要导入模块: from pymongo.connection import Connection [as 别名]
# 或者: from pymongo.connection.Connection import save [as 别名]
        'aut': aut,
        'galT': galT
    }

    index = 1
    is_new = True
    holdfield = {}
    for field in fields.find({'p': p,
                              'n': n,
                              'c': c}):
        index += 1
        if field['coeffs'] == coeffs:
            is_new = False
            holdfield = field
            break

    if is_new:
        print "new field"
        label = base_label(p, n, c, index)
        info = {'label': label}
        info.update(data)
        print "entering %s into database" % info
        fields.save(info)
    else:
        holdfield.update(data)
        print "field already in database, updating with %s" % holdfield
        fields.save(holdfield)
 #   if time.time() - t > 5:
 #       print "\t", label
 #       t = time.time()
开发者ID:anneschilling,项目名称:lmfdb,代码行数:32,代码来源:import_fields.py


注:本文中的pymongo.connection.Connection.save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。