How to connect Azure Synapse Notebook to Mongodb compass.

Rahul Kumar 0 Reputation points
2026-07-17T15:22:13.6766667+00:00

How to connect Azure Synapse Notebook to Mongodb compass.
I am geeting error - serverselectiontimeout error,name or service not known

Azure Synapse Analytics
Azure Synapse Analytics

An Azure analytics service that brings together data integration, enterprise data warehousing, and big data analytics. Previously known as Azure SQL Data Warehouse.

0 comments No comments

2 answers

Sort by: Most helpful
  1. Ganesh Chelluri 90 Reputation points Microsoft External Staff Moderator
    2026-07-17T23:09:39.45+00:00

    Hi @Rahul Kumar ,

    Quick clarification: Compass is only a GUI. Your Synapse notebook connects directly to the MongoDB server, not to Compass. The error "ServerSelectionTimeout: name or service not known" means the Spark pool cannot resolve the MongoDB hostname over DNS. Nothing is wrong on the MongoDB side, the request never reached it. Common causes: - Hostname only resolves from your laptop (localhost / private IP / on-prem DNS). - MongoDB firewall / NSG / Atlas Network Access does not allow Azure outbound IPs. - Synapse workspace has Managed VNet enabled but no Private Endpoint to Mongo.

    Fix:

    1. Test DNS from the notebook itself: import socket socket.gethostbyname("<mongo-host>") If this fails, it is a network/DNS issue, not code.
    2. Use the correct connection string from the Mongo service: - Cosmos DB for MongoDB -> Portal > Connection strings - Atlas -> whitelist Azure IPs (or use Private Link) and use the mongodb+srv URI - Self-hosted on Azure VM -> NSG allow 27017 from Synapse, bind mongod to 0.0.0.0 - On-prem MongoDB -> requires Self-hosted IR or ExpressRoute/VPN + private DNS
    3. Working sample: %pip install pymongo dnspython from pymongo import MongoClient client = MongoClient("<uri>", serverSelectionTimeoutMS=15000) print(client.server_info())
      Follow steps 1 and 2 based on where your MongoDB is hosted and the connection will succeed.

    Was this answer helpful?


  2. Sina Salam 30,896 Reputation points Volunteer Moderator
    2026-07-17T16:05:04.53+00:00

    Hello Rahul Kumar,

    Welcome to the Microsoft Q&A and thank you for posting your questions here.

    I understand that you would like to know how to connect Azure Synapse Notebook to Mongodb compass.

    Try to understand that Azure Synapse Spark Notebooks run on Microsoft-managed Spark compute and do not support direct connectivity to third-party Private Link services such as MongoDB Atlas Private Endpoints. So, configuring Private Endpoints, DNS, firewall rules, or Synapse outbound IP addresses will not enable this scenario.

    The supported resolution is to either deploy your compute within the same virtual network as the MongoDB Atlas Private Endpoint (for example, Azure Databricks with VNet injection, Azure Virtual Machine, or AKS), use a Self-hosted Integration Runtime (SHIR) where applicable, or expose MongoDB Atlas through a public endpoint secured with IP allow lists, TLS, and authentication.

    Use the following official resources for additional guidance:

    I hope this is helpful. Please! Do not hesitate to let me know if you have any other questions, steps or clarifications.


    Please do not close the thread by upvoting and accepting the answer if any part of it is helpful.

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.