MCPcopy Index your code
hub / github.com/mongodb/mongo-python-driver / _element_to_bson

Function _element_to_bson

bson/__init__.py:983–994  ·  view source on GitHub ↗

Encode a single key, value pair.

(key: Any, value: Any, check_keys: bool, opts: CodecOptions[Any])

Source from the content-addressed store, hash-verified

981
982
983def _element_to_bson(key: Any, value: Any, check_keys: bool, opts: CodecOptions[Any]) -> bytes:
984 """Encode a single key, value pair."""
985 if not isinstance(key, str):
986 raise InvalidDocument(f"documents must have only string keys, key was {key!r}")
987 if check_keys:
988 if key.startswith("$"):
989 raise InvalidDocument(f"key {key!r} must not start with '$'")
990 if "." in key:
991 raise InvalidDocument(f"key {key!r} must not contain '.'")
992
993 name = _make_name(key)
994 return _name_value_to_bson(name, value, check_keys, opts)
995
996
997def _dict_to_bson(

Callers 3

_encode_mappingFunction · 0.85
_encode_dbrefFunction · 0.85
_dict_to_bsonFunction · 0.85

Calls 3

InvalidDocumentClass · 0.90
_make_nameFunction · 0.85
_name_value_to_bsonFunction · 0.85

Tested by

no test coverage detected