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

Function _decode_all_selective

bson/__init__.py:1245–1287  ·  view source on GitHub ↗

Decode BSON data to a single document while using user-provided custom decoding logic. `data` must be a string representing a valid, BSON-encoded document. :param data: BSON data :param codec_options: An instance of :class:`~bson.codec_options.CodecOptions` with user-specif

(
    data: Any, codec_options: CodecOptions[_DocumentType], fields: Any
)

Source from the content-addressed store, hash-verified

1243
1244
1245def _decode_all_selective(
1246 data: Any, codec_options: CodecOptions[_DocumentType], fields: Any
1247) -> list[_DocumentType]:
1248 """Decode BSON data to a single document while using user-provided
1249 custom decoding logic.
1250
1251 `data` must be a string representing a valid, BSON-encoded document.
1252
1253 :param data: BSON data
1254 :param codec_options: An instance of
1255 :class:`~bson.codec_options.CodecOptions` with user-specified type
1256 decoders. If no decoders are found, this method is the same as
1257 ``decode_all``.
1258 :param fields: Map of document namespaces where data that needs
1259 to be custom decoded lives or None. For example, to custom decode a
1260 list of objects in 'field1.subfield1', the specified value should be
1261 ``{'field1': {'subfield1': 1}}``. If ``fields`` is an empty map or
1262 None, this method is the same as ``decode_all``.
1263
1264 :return: Single-member list containing the decoded document.
1265
1266 .. versionadded:: 3.8
1267 """
1268 if not codec_options.type_registry._decoder_map:
1269 return decode_all(data, codec_options)
1270
1271 if not fields:
1272 return decode_all(data, codec_options.with_options(type_registry=None))
1273
1274 # Decode documents for internal use.
1275 from bson.raw_bson import RawBSONDocument
1276
1277 internal_codec_options: CodecOptions[RawBSONDocument] = codec_options.with_options(
1278 document_class=RawBSONDocument, type_registry=None
1279 )
1280 _doc = _bson_to_dict(data, internal_codec_options)
1281 return [
1282 _decode_selective(
1283 _doc,
1284 fields,
1285 codec_options,
1286 )
1287 ]
1288
1289
1290@overload

Callers 4

commandFunction · 0.90
run_operationMethod · 0.90
commandFunction · 0.90
run_operationMethod · 0.90

Calls 4

decode_allFunction · 0.85
_bson_to_dictFunction · 0.85
_decode_selectiveFunction · 0.85
with_optionsMethod · 0.45

Tested by

no test coverage detected