{"record":{"id":"7c432e04645595bb","repo":"apache/beam","slug":"readfrommongdb-coll-param-must-be-specified-as-a-string","errorCode":null,"errorMessage":"ReadFromMongDB coll param must be specified as a string","messagePattern":"ReadFromMongDB coll param must be specified as a string","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/io/mongodbio.py","lineNumber":155,"sourceCode":"      projection: A list of field names that should be returned in the result\n        set or a dict specifying the fields to include or exclude.\n      extra_client_params(dict): Optional `MongoClient\n        <https://api.mongodb.com/python/current/api/pymongo/mongo_client.html>`_\n        parameters.\n      bucket_auto (bool): If :data:`True`, use MongoDB `$bucketAuto` aggregation\n        to split collection into bundles instead of `splitVector` command,\n        which does not work with MongoDB Atlas.\n        If :data:`False` (the default), use `splitVector` command for bundling.\n\n    Returns:\n      :class:`~apache_beam.transforms.ptransform.PTransform`\n    \"\"\"\n    if extra_client_params is None:\n      extra_client_params = {}\n    if not isinstance(db, str):\n      raise ValueError(\"ReadFromMongDB db param must be specified as a string\")\n    if not isinstance(coll, str):\n      raise ValueError(\n          \"ReadFromMongDB coll param must be specified as a string\")\n    self._mongo_source = _BoundedMongoSource(\n        uri=uri,\n        db=db,\n        coll=coll,\n        filter=filter,\n        projection=projection,\n        extra_client_params=extra_client_params,\n        bucket_auto=bucket_auto,\n    )\n\n  def expand(self, pcoll):\n    return pcoll | iobase.Read(self._mongo_source)\n\n\nclass _ObjectIdRangeTracker(OrderedPositionRangeTracker):\n  \"\"\"RangeTracker for tracking mongodb _id of bson ObjectId type.\"\"\"\n  def position_to_fraction(","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/io/mongodbio.py#L137-L173","documentation":"ReadFromMongoDB.__init__ validates that the coll (collection) parameter is a Python str and raises ValueError otherwise. The collection name is forwarded to _BoundedMongoSource and must be a valid string name.","triggerScenarios":"Calling ReadFromMongoDB(uri=..., db='mydb', coll=<non-string>) — e.g. coll=None, a bytes value, or a pymongo Collection object passed by mistake.","commonSituations":"Passing a pymongo collection object instead of its name; unset config variable yielding None; bytes from a config parser.","solutions":["Pass the collection name as a str, e.g. coll='users'.","If you have a pymongo Collection object, pass its .name attribute.","Coerce/validate config-sourced values: str(value) after a None check, or .decode() for bytes.","Fix argument order so the intended value reaches coll."],"exampleFix":"// before\ncoll = mongo_db['users']\np = ReadFromMongoDB(uri=uri, db='mydb', coll=coll)\n// after\np = ReadFromMongoDB(uri=uri, db='mydb', coll=coll.name)","handlingStrategy":"type-guard","validationCode":"if not isinstance(coll, str) or not coll:\n    raise ValueError('coll must be a non-empty string')","typeGuard":"def is_coll_name(v) -> bool:\n    return isinstance(v, str) and bool(v)","tryCatchPattern":"try:\n    t = ReadFromMongoDB(uri=uri, db=db, coll=coll)\nexcept ValueError as e:\n    raise ConfigError(f'bad Mongo source config: {e}') from e","preventionTips":["Pass collection.name when starting from a pymongo Collection object.","Validate collection names at config load time.","Use keyword arguments to avoid positional mix-ups."],"tags":["mongodb","validation","python"],"backgroundTag":"invalid-argument-value","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}