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

Method encode

bson/__init__.py:1409–1434  ·  view source on GitHub ↗

Encode a document to a new :class:`BSON` instance. A document can be any mapping type (like :class:`dict`). Raises :class:`TypeError` if `document` is not a mapping type, or contains keys that are not instances of :class:`str'. Raises :class:`~bson.errors.InvalidDoc

(
        cls: Type[BSON],
        document: Mapping[str, Any],
        check_keys: bool = False,
        codec_options: CodecOptions[Any] = DEFAULT_CODEC_OPTIONS,
    )

Source from the content-addressed store, hash-verified

1407
1408 @classmethod
1409 def encode(
1410 cls: Type[BSON],
1411 document: Mapping[str, Any],
1412 check_keys: bool = False,
1413 codec_options: CodecOptions[Any] = DEFAULT_CODEC_OPTIONS,
1414 ) -> BSON:
1415 """Encode a document to a new :class:`BSON` instance.
1416
1417 A document can be any mapping type (like :class:`dict`).
1418
1419 Raises :class:`TypeError` if `document` is not a mapping type,
1420 or contains keys that are not instances of
1421 :class:`str'. Raises :class:`~bson.errors.InvalidDocument`
1422 if `document` cannot be converted to :class:`BSON`.
1423
1424 :param document: mapping type representing a document
1425 :param check_keys: check if keys start with '$' or
1426 contain '.', raising :class:`~bson.errors.InvalidDocument` in
1427 either case
1428 :param codec_options: An instance of
1429 :class:`~bson.codec_options.CodecOptions`.
1430
1431 .. versionchanged:: 3.0
1432 Replaced `uuid_subtype` option with `codec_options`.
1433 """
1434 return cls(encode(document, check_keys, codec_options))
1435
1436 def decode( # type:ignore[override]
1437 self, codec_options: CodecOptions[Any] = DEFAULT_CODEC_OPTIONS

Callers 15

writeMethod · 0.80
writeMethod · 0.80
test_put_unicodeMethod · 0.80
run_testFunction · 0.80
test_write_unicodeMethod · 0.80
_mock_urlopenFunction · 0.80
targetMethod · 0.80
test_metadataMethod · 0.80
run_testFunction · 0.80

Calls 1

encodeFunction · 0.85

Tested by 15

test_put_unicodeMethod · 0.64
run_testFunction · 0.64
test_write_unicodeMethod · 0.64
_mock_urlopenFunction · 0.64
targetMethod · 0.64
test_metadataMethod · 0.64
run_testFunction · 0.64
_mock_urlopenFunction · 0.64