本文整理汇总了Python中pymongo.ReturnDocument.AFTER属性的典型用法代码示例。如果您正苦于以下问题:Python ReturnDocument.AFTER属性的具体用法?Python ReturnDocument.AFTER怎么用?Python ReturnDocument.AFTER使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类pymongo.ReturnDocument
的用法示例。
在下文中一共展示了ReturnDocument.AFTER属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: refresh_data
# 需要导入模块: from pymongo import ReturnDocument [as 别名]
# 或者: from pymongo.ReturnDocument import AFTER [as 别名]
def refresh_data(data, collection_name, refresh_period, host, port):
client = MongoClient(host, port)
db = client['deep-architect']
collection = db[collection_name]
while collection.find_one_and_update(
{
'$and': [{
'_id': data['_id']
}, {
STARTTIME_KEY: {
'$ne': None
}
}, {
ENDTIME_KEY: {
'$eq': None
}
}]
}, {'$currentDate': {
REFRESH_KEY: True
}},
return_document=ReturnDocument.AFTER):
logger.debug('Refreshed data for id %s', str(data['_id']))
time.sleep(refresh_period)
示例2: inc
# 需要导入模块: from pymongo import ReturnDocument [as 别名]
# 或者: from pymongo.ReturnDocument import AFTER [as 别名]
def inc(op: str, ident: str, period_secs: int, max_operations: int):
coll = db.coll('opcount')
cur_time = int(time.time())
begin_at = datetime.datetime.utcfromtimestamp(cur_time - cur_time % period_secs)
expire_at = begin_at + datetime.timedelta(seconds=period_secs)
try:
doc = await coll.find_one_and_update(filter={'ident': ident,
'begin_at': begin_at,
'expire_at': expire_at,
op: {'$not': {'$gte': max_operations}}},
update={'$inc': {op: 1}},
upsert=True,
return_document=ReturnDocument.AFTER)
return doc
except errors.DuplicateKeyError:
raise error.OpcountExceededError(op, period_secs, max_operations)
示例3: set_roles
# 需要导入模块: from pymongo import ReturnDocument [as 别名]
# 或者: from pymongo.ReturnDocument import AFTER [as 别名]
def set_roles(domain_id: str, roles):
roles = {str(role): int(perm) for role, perm in roles.items()}
update = {}
for role in roles:
validator.check_role(role)
if role in builtin.BUILTIN_ROLE_DESCRIPTORS:
if not builtin.BUILTIN_ROLE_DESCRIPTORS[role].modifiable:
raise error.ModifyBuiltinRoleError(domain_id, role)
update['roles.{0}'.format(role)] = roles[role]
for domain in builtin.DOMAINS:
if domain['_id'] == domain_id:
raise error.BuiltinDomainError(domain_id)
coll = db.coll('domain')
return await coll.find_one_and_update(filter={'_id': domain_id},
update={'$set': update},
return_document=ReturnDocument.AFTER)
示例4: delete_roles
# 需要导入模块: from pymongo import ReturnDocument [as 别名]
# 或者: from pymongo.ReturnDocument import AFTER [as 别名]
def delete_roles(domain_id: str, roles):
roles = list(set(roles))
for role in roles:
validator.check_role(role)
if role in builtin.BUILTIN_ROLE_DESCRIPTORS:
raise error.ModifyBuiltinRoleError(domain_id, role)
for domain in builtin.DOMAINS:
if domain['_id'] == domain_id:
raise error.BuiltinDomainError(domain_id)
user_coll = db.coll('domain.user')
await user_coll.update_many({'domain_id': domain_id, 'role': {'$in': list(roles)}},
{'$unset': {'role': ''}})
coll = db.coll('domain')
return await coll.find_one_and_update(filter={'_id': domain_id},
update={'$unset': dict(('roles.{0}'.format(role), '')
for role in roles)},
return_document=ReturnDocument.AFTER)
示例5: capped_inc_status
# 需要导入模块: from pymongo import ReturnDocument [as 别名]
# 或者: from pymongo.ReturnDocument import AFTER [as 别名]
def capped_inc_status(domain_id: str,
doc_type: int,
doc_id: convert_doc_id,
uid: int,
key: str,
value: int,
min_value: int = -1,
max_value: int = 1):
assert value != 0
if value > 0:
not_expr = {'$gte': max_value}
else:
not_expr = {'$lte': min_value}
coll = db.coll('document.status')
doc = await coll.find_one_and_update(filter={'domain_id': domain_id,
'doc_type': doc_type,
'doc_id': doc_id,
'uid': uid,
key: {'$not': not_expr}},
update={'$inc': {key: value}},
upsert=True,
return_document=ReturnDocument.AFTER)
return doc
示例6: rev_set_status
# 需要导入模块: from pymongo import ReturnDocument [as 别名]
# 或者: from pymongo.ReturnDocument import AFTER [as 别名]
def rev_set_status(domain_id, doc_type, doc_id, uid, rev, return_doc=True, **kwargs):
coll = db.coll('document.status')
filter = {'domain_id': domain_id,
'doc_type': doc_type,
'doc_id': doc_id,
'uid': uid,
'rev': rev}
update = {'$set': kwargs,
'$inc': {'rev': 1}}
if return_doc:
doc = await coll.find_one_and_update(filter=filter, update=update,
return_document=ReturnDocument.AFTER)
return doc
else:
result = await coll.update_one(filter, update)
return result
示例7: rejudge
# 需要导入模块: from pymongo import ReturnDocument [as 别名]
# 或者: from pymongo.ReturnDocument import AFTER [as 别名]
def rejudge(record_id: objectid.ObjectId, enqueue: bool=True):
coll = db.coll('record')
doc = await coll.find_one_and_update(filter={'_id': record_id},
update={'$unset': {'judge_uid': '',
'judge_token': '',
'judge_at': '',
'compiler_texts': '',
'judge_texts': '',
'cases': ''},
'$set': {'status': constant.record.STATUS_WAITING,
'score': 0,
'time_ms': 0,
'memory_kb': 0,
'rejudged': True}},
return_document=ReturnDocument.AFTER)
bus.publish_throttle('record_change', doc, doc['_id'])
if enqueue:
await queue.publish('judge', rid=doc['_id'])
示例8: add
# 需要导入模块: from pymongo import ReturnDocument [as 别名]
# 或者: from pymongo.ReturnDocument import AFTER [as 别名]
def add(self, type, migration, output, state, success):
script = inspect.getsource(migration)
return Record(self.collection.find_one_and_update(
{'plugin': self.plugin, 'filename': self.filename},
{
'$push': {'ops': {
'date': datetime.now(),
'type': type,
'script': script,
'output': output,
'state': state,
'success': success,
}}
},
upsert=True,
return_document=ReturnDocument.AFTER,
))
示例9: add_record
# 需要导入模块: from pymongo import ReturnDocument [as 别名]
# 或者: from pymongo.ReturnDocument import AFTER [as 别名]
def add_record(self, type, output, state, success):
script = inspect.getsource(self.module)
return Record(self.collection.find_one_and_update(
self.db_query,
{
'$push': {'ops': {
'date': datetime.now(),
'type': type,
'script': script,
'output': output,
'state': state,
'success': success,
}}
},
upsert=True,
return_document=ReturnDocument.AFTER,
))
示例10: retrieve
# 需要导入模块: from pymongo import ReturnDocument [as 别名]
# 或者: from pymongo.ReturnDocument import AFTER [as 别名]
def retrieve(self, sender_id):
stored = self.conversations.find_one({"sender_id": sender_id})
# look for conversations which have used an `int` sender_id in the past
# and update them.
if stored is None and sender_id.isdigit():
from pymongo import ReturnDocument
stored = self.conversations.find_one_and_update(
{"sender_id": int(sender_id)},
{"$set": {"sender_id": str(sender_id)}},
return_document=ReturnDocument.AFTER)
if stored is not None:
if self.domain:
return DialogueStateTracker.from_dict(sender_id,
stored.get("events"),
self.domain.slots)
else:
logger.warning("Can't recreate tracker from mongo storage "
"because no domain is set. Returning `None` "
"instead.")
return None
else:
return None
示例11: update_clinvar_id
# 需要导入模块: from pymongo import ReturnDocument [as 别名]
# 或者: from pymongo.ReturnDocument import AFTER [as 别名]
def update_clinvar_id(self, clinvar_id, submission_id):
"""saves an official clinvar submission ID in a clinvar submission object
Args:
clinvar_id(str): a string with a format: SUB[0-9]. It is obtained from clinvar portal when starting a new submission
submission_id(str): submission_id(str) : id of the submission to be updated
Returns:
updated_submission(obj): a clinvar submission object, updated
"""
updated_submission = self.clinvar_submission_collection.find_one_and_update(
{"_id": ObjectId(submission_id)},
{"$set": {"clinvar_subm_id": clinvar_id, "updated_at": datetime.now()}},
upsert=True,
return_document=pymongo.ReturnDocument.AFTER,
)
return updated_submission
示例12: mongo_update_app
# 需要导入模块: from pymongo import ReturnDocument [as 别名]
# 或者: from pymongo.ReturnDocument import AFTER [as 别名]
def mongo_update_app(self, app_name, starting_ports, containers_per, env_vars, docker_image, running,
networks, volumes, devices, privileged, rolling_restart):
result = self.collection["apps"].find_one_and_update({'app_name': app_name},
{'$inc': {'app_id': 1},
'$set': {'starting_ports': starting_ports,
'containers_per': containers_per,
'env_vars': env_vars,
'docker_image': docker_image,
'running': running,
'networks': networks,
"volumes": volumes,
"devices": devices,
"privileged": privileged,
"rolling_restart": rolling_restart
}
},
upsert=True,
return_document=ReturnDocument.AFTER)
return result
# get latest envvars of app
示例13: _subscribe
# 需要导入模块: from pymongo import ReturnDocument [as 别名]
# 或者: from pymongo.ReturnDocument import AFTER [as 别名]
def _subscribe(self, subscription, callback):
collection = self._db[subscription]
self._processing[subscription] = False
while self._subscribed[subscription]:
# The current job is still being processed
if self._processing[subscription]:
time.sleep(10)
continue
data = collection.find_one_and_update(
{STARTTIME_KEY: {
'$eq': None
}}, {'$currentDate': {
REFRESH_KEY: True,
STARTTIME_KEY: True
}},
return_document=ReturnDocument.AFTER)
# Nothing currently in the subscription queue
if data is None:
time.sleep(10)
else:
self._processing[subscription] = True
refresh_process = Process(target=refresh_data,
args=(data, collection.name,
self._refresh_period, self.host,
self.port))
refresh_process.daemon = True
refresh_process.start()
callback(data)
示例14: finish_processing
# 需要导入模块: from pymongo import ReturnDocument [as 别名]
# 或者: from pymongo.ReturnDocument import AFTER [as 别名]
def finish_processing(self, subscription, data, success=True):
"""Removes the message from the intermediate processing storage. Must be
called for every message received if store_intermediate is True.
Arguments:
- subscription: The name of the topic to subscribe to.
- callback: Function that is called with the object representing
the data that was consumed.
- success: whether the processing of the message was successful. If
not, the data is put back into the original queue
"""
logger.info('Finish processing %s', str(data))
collection = self._db[subscription]
if success:
data = collection.find_one_and_update(
{'_id': data['_id']}, {
'$currentDate': {
ENDTIME_KEY: True
},
'$inc': {
TIME_WORKED_KEY: (data[REFRESH_KEY] -
data[STARTTIME_KEY]).total_seconds()
}
},
return_document=ReturnDocument.AFTER)
logger.info('Successfully finished %s from %s', str(data['_id']),
subscription)
else:
collection.find_one_and_update({'_id': data['_id']}, {
'$set': {
STARTTIME_KEY: None,
ENDTIME_KEY: None,
REFRESH_KEY: None
}
})
logger.info('Unsuccessful processing %s, reinserting into %s',
str(data['_id']), subscription)
self._processing[subscription] = False
示例15: unlink
# 需要导入模块: from pymongo import ReturnDocument [as 别名]
# 或者: from pymongo.ReturnDocument import AFTER [as 别名]
def unlink(file_id: objectid.ObjectId):
"""Unlink a file."""
coll = db.coll('fs.files')
doc = await coll.find_one_and_update(filter={'_id': file_id},
update={'$inc': {'metadata.link': -1}},
return_document=ReturnDocument.AFTER)
if doc and not doc['metadata']['link']:
fs = db.fs('fs')
await fs.delete(file_id)