An Azure analytics service that brings together data integration, enterprise data warehousing, and big data analytics. Previously known as Azure SQL Data Warehouse.
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:
- Test DNS from the notebook itself: import socket socket.gethostbyname("<mongo-host>") If this fails, it is a network/DNS issue, not code.
- 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
- 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.