@@ -263,7 +263,8 @@ def __init__(
263263 aware (otherwise they will be naive)
264264 :param connect: If ``True`` (the default), immediately
265265 begin connecting to MongoDB in the background. Otherwise connect
266- on the first operation.
266+ on the first operation. The default value is ``False`` when
267+ running in a Function-as-a-service environment.
267268 :param type_registry: instance of
268269 :class:`~bson.codec_options.TypeRegistry` to enable encoding
269270 and decoding of custom types.
@@ -719,6 +720,10 @@ def __init__(
719720
720721 .. versionchanged:: 4.7
721722 Deprecated parameter ``wTimeoutMS``, use :meth:`~pymongo.timeout`.
723+
724+ .. versionchanged:: 4.9
725+ The default value of ``connect`` is changed to ``False`` when running in a
726+ Function-as-a-service environment.
722727 """
723728 doc_class = document_class or dict
724729 self ._init_kwargs : dict [str , Any ] = {
@@ -802,7 +807,10 @@ def __init__(
802807 if tz_aware is None :
803808 tz_aware = opts .get ("tz_aware" , False )
804809 if connect is None :
805- connect = opts .get ("connect" , True )
810+ # Default to connect=True unless on a FaaS system, which might use fork.
811+ from pymongo .pool_options import _is_faas
812+
813+ connect = opts .get ("connect" , not _is_faas ())
806814 keyword_opts ["tz_aware" ] = tz_aware
807815 keyword_opts ["connect" ] = connect
808816
0 commit comments