本文整理匯總了Python中bson.dbref方法的典型用法代碼示例。如果您正苦於以下問題:Python bson.dbref方法的具體用法?Python bson.dbref怎麽用?Python bson.dbref使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類bson
的用法示例。
在下文中一共展示了bson.dbref方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _parse_canonical_dbpointer
# 需要導入模塊: import bson [as 別名]
# 或者: from bson import dbref [as 別名]
def _parse_canonical_dbpointer(doc):
"""Decode a JSON (deprecated) DBPointer to bson.dbref.DBRef."""
dbref = doc['$dbPointer']
if len(doc) != 1:
raise TypeError('Bad $dbPointer, extra field(s): %s' % (doc,))
if isinstance(dbref, DBRef):
dbref_doc = dbref.as_doc()
# DBPointer must not contain $db in its value.
if dbref.database is not None:
raise TypeError(
'Bad $dbPointer, extra field $db: %s' % (dbref_doc,))
if not isinstance(dbref.id, ObjectId):
raise TypeError(
'Bad $dbPointer, $id must be an ObjectId: %s' % (dbref_doc,))
if len(dbref_doc) != 2:
raise TypeError(
'Bad $dbPointer, extra field(s) in DBRef: %s' % (dbref_doc,))
return dbref
else:
raise TypeError('Bad $dbPointer, expected a DBRef: %s' % (doc,))
示例2: _parse_canonical_dbref
# 需要導入模塊: import bson [as 別名]
# 或者: from bson import dbref [as 別名]
def _parse_canonical_dbref(doc):
"""Decode a JSON DBRef to bson.dbref.DBRef."""
for key in doc:
if key.startswith('$') and key not in _DBREF_KEYS:
# Other keys start with $, so dct cannot be parsed as a DBRef.
return doc
return DBRef(doc.pop('$ref'), doc.pop('$id'),
database=doc.pop('$db', None), **doc)