本文整理汇总了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)
示例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)
示例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)
示例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()
示例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()