{"title":"MongoDB","description":"Add MongoDB as an external catalog in Altertable. Query Atlas or self-hosted collections as SQL tables alongside your other data sources.","order":25,"askSuggestions":["How do I allow Altertable in my Atlas IP access list?","Why don't my Atlas collections appear as tables?","How do MongoDB collections map to SQL tables?"],"navigation":true,"body":{"code":"var Component=(()=>{var p=Object.create;var l=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var A=Object.getPrototypeOf,w=Object.prototype.hasOwnProperty;var D=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),x=(t,e)=>{for(var s in e)l(t,s,{get:e[s],enumerable:!0})},d=(t,e,s,a)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let o of f(e))!w.call(t,o)&&o!==s&&l(t,o,{get:()=>e[o],enumerable:!(a=b(e,o))||a.enumerable});return t};var y=(t,e,s)=>(s=t!=null?p(A(t)):{},d(e||!t||!t.__esModule?l(s,\"default\",{value:t,enumerable:!0}):s,t)),S=t=>d(l({},\"__esModule\",{value:!0}),t);var g=D((M,h)=>{h.exports=_jsx_runtime});var v={};x(v,{default:()=>m,frontmatter:()=>C});var n=y(g()),C={title:\"MongoDB\",description:\"Add MongoDB as an external catalog in Altertable. Query Atlas or self-hosted collections as SQL tables alongside your other data sources.\",order:25,askSuggestions:[\"How do I allow Altertable in my Atlas IP access list?\",\"Why don't my Atlas collections appear as tables?\",\"How do MongoDB collections map to SQL tables?\"]};function u(t){let e={a:\"a\",code:\"code\",h1:\"h1\",h2:\"h2\",h3:\"h3\",li:\"li\",ol:\"ol\",p:\"p\",pre:\"pre\",strong:\"strong\",ul:\"ul\",...t.components},{DocsCallout:s,DocsPreviewDocument:a,DocsPreviewSection:o,DocsTable:i,Screenshot:c}=e;return s||r(\"DocsCallout\",!0),a||r(\"DocsPreviewDocument\",!0),o||r(\"DocsPreviewSection\",!0),i||r(\"DocsTable\",!0),c||r(\"Screenshot\",!0),(0,n.jsxs)(a,{anchors:\"mongodb prerequisites allow-altertable-egress-ips create-a-database-user connecting-to-altertable atlas-mapping\",children:[(0,n.jsxs)(o,{sectionId:\"mongodb\",sectionTitle:\"MongoDB\",anchors:\"\",ancestors:\"\",index:\"0\",children:[(0,n.jsx)(e.h1,{id:\"mongodb\",children:\"MongoDB\"}),`\n`,(0,n.jsx)(e.p,{children:\"Add a MongoDB database as an external catalog in Altertable to query its collections with SQL alongside your other data sources. Each collection in the connected database appears as a table.\"}),`\n`]}),(0,n.jsxs)(o,{sectionId:\"prerequisites\",sectionTitle:\"Prerequisites\",anchors:\"\",ancestors:\"\",index:\"1\",children:[(0,n.jsx)(e.h2,{id:\"prerequisites\",children:\"Prerequisites\"}),`\n`]}),(0,n.jsxs)(o,{sectionId:\"allow-altertable-egress-ips\",sectionTitle:\"Allow Altertable egress IPs\",anchors:\"\",ancestors:\"prerequisites\",index:\"2\",children:[(0,n.jsx)(e.h3,{id:\"allow-altertable-egress-ips\",children:\"Allow Altertable egress IPs\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"If inbound traffic is restricted\\u2014including \",(0,n.jsx)(e.strong,{children:\"MongoDB Atlas\"}),\" IP access lists\\u2014allow \",(0,n.jsx)(e.a,{href:\"/docs/administration/network#egress-ip-addresses\",children:\"Altertable's egress IP addresses\"}),\" so Workers can connect.\"]}),`\n`,(0,n.jsx)(e.p,{children:\"For Atlas:\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"Open the Atlas project and go to \",(0,n.jsx)(e.strong,{children:\"Network Access\"})]}),`\n`,(0,n.jsxs)(e.li,{children:[\"Click \",(0,n.jsx)(e.strong,{children:\"Add IP Address\"})]}),`\n`,(0,n.jsxs)(e.li,{children:[\"Add each \",(0,n.jsx)(e.a,{href:\"/docs/administration/network#egress-ip-addresses\",children:\"egress IP address\"}),\" (Atlas accepts the address or \",(0,n.jsx)(e.code,{children:\"address/32\"}),\")\"]}),`\n`,(0,n.jsx)(e.li,{children:\"Confirm the entries are active before you test the catalog in Altertable\"}),`\n`]}),`\n`,(0,n.jsxs)(e.p,{children:[\"You can also connect a self-hosted MongoDB server through an \",(0,n.jsx)(e.a,{href:\"/docs/lakehouse/external-catalogs\",children:\"SSH tunnel\"}),\".\"]}),`\n`]}),(0,n.jsxs)(o,{sectionId:\"create-a-database-user\",sectionTitle:\"Create a database user\",anchors:\"\",ancestors:\"prerequisites\",index:\"3\",children:[(0,n.jsx)(e.h3,{id:\"create-a-database-user\",children:\"Create a database user\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"Use a MongoDB database user, not your Atlas organization login. In Atlas, create the user under \",(0,n.jsx)(e.strong,{children:\"Database Access\"}),\" with read access to the database you will query.\"]}),`\n`]}),(0,n.jsxs)(o,{sectionId:\"connecting-to-altertable\",sectionTitle:\"Connecting to Altertable\",anchors:\"\",ancestors:\"\",index:\"4\",children:[(0,n.jsx)(e.h2,{id:\"connecting-to-altertable\",children:\"Connecting to Altertable\"}),`\n`,(0,n.jsx)(e.p,{children:\"To add a new MongoDB external catalog:\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"Navigate to the \",(0,n.jsx)(e.strong,{children:\"Catalogs\"}),\" section in the dashboard\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"Click \",(0,n.jsx)(e.strong,{children:\"New catalog\"})]}),`\n`,(0,n.jsxs)(e.li,{children:[\"Select \",(0,n.jsx)(e.strong,{children:\"MongoDB\"}),\" as the engine\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"Fill in the connection details:\",`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Connection string\"}),\" (optional): Paste a \",(0,n.jsx)(e.code,{children:\"mongodb://\"}),\" or \",(0,n.jsx)(e.code,{children:\"mongodb+srv://\"}),\" URL to fill Host, username, SRV, and related options. Enter the password separately. Atlas connection strings often omit the database name, so you still need to set \",(0,n.jsx)(e.strong,{children:\"Database\"}),\".\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Host\"}),\": The hostname. For Atlas, use the hostname from the connection string, such as \",(0,n.jsx)(e.code,{children:\"cluster0.xxxxx.mongodb.net\"}),\"\\u2014without \",(0,n.jsx)(e.code,{children:\"mongodb+srv://\"}),\" or credentials.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Port\"}),\": Default \",(0,n.jsx)(e.code,{children:\"27017\"}),\". Leave it empty when \",(0,n.jsx)(e.strong,{children:\"SRV connection\"}),\" is enabled.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Database\"}),\": The MongoDB database whose collections you want to query (for example, \",(0,n.jsx)(e.code,{children:\"sample_mflix\"}),\"). Collections in that database appear as tables.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Username\"}),\": The database user\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Password\"}),\": The database user password\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"SRV connection\"}),\": Use a \",(0,n.jsx)(e.code,{children:\"mongodb+srv\"}),\" connection and discover hosts through DNS\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"TLS\"}),\": Encrypt the connection with TLS. Atlas SRV connections already use TLS, so you typically leave this off unless you need a custom CA.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Authentication source\"}),\" (optional): Database where the user is defined, often \",(0,n.jsx)(e.code,{children:\"admin\"})]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"CA certificate\"}),\" (optional): Custom CA used to verify the MongoDB server\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[\"Click \",(0,n.jsx)(e.strong,{children:\"Save\"})]}),`\n`]}),`\n`,(0,n.jsx)(s,{title:\"Atlas: enable SRV connection\",children:(0,n.jsxs)(e.p,{children:[\"Atlas clusters advertise hosts through DNS SRV records (\",(0,n.jsx)(e.code,{children:\"mongodb+srv\"}),\"). Enable \",(0,n.jsx)(e.strong,{children:\"SRV connection\"}),\". If you leave it off, Altertable can still connect, but collections often fail to appear in the schema.\"]})}),`\n`,(0,n.jsx)(c,{story:\"app-components-connections-connection-form--mongo-empty\",caption:\"New MongoDB connection form\",width:\"1408\",height:\"2454\"}),`\n`,(0,n.jsx)(e.p,{children:\"Once added, collections from the connected database show up as tables in the catalog browser. You can query them with DuckDB SQL:\"}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-sql\",children:`SELECT * FROM mongo.sample_mflix.comments LIMIT 100;\n`})}),`\n`,(0,n.jsxs)(e.p,{children:[\"If the catalog is named \",(0,n.jsx)(e.code,{children:\"mongo\"}),\" and the database is \",(0,n.jsx)(e.code,{children:\"sample_mflix\"}),\", the fully qualified table name is \",(0,n.jsx)(e.code,{children:\"mongo.sample_mflix.comments\"}),\".\"]}),`\n`]}),(0,n.jsxs)(o,{sectionId:\"atlas-mapping\",sectionTitle:\"Atlas mapping\",anchors:\"\",ancestors:\"\",index:\"5\",children:[(0,n.jsx)(e.h2,{id:\"atlas-mapping\",children:\"Atlas mapping\"}),`\n`,(0,n.jsx)(i,{columns:[\"Atlas\",\"Altertable\"],data:[{Atlas:\"Cluster hostname (`cluster0.xxxxx.mongodb.net`)\",Altertable:\"**Host**\"},{Atlas:\"Database (`sample_mflix`)\",Altertable:\"**Database** (schema in the catalog browser)\"},{Atlas:\"Collection (`comments`)\",Altertable:\"Table\"},{Atlas:\"Database user\",Altertable:\"**Username** and **Password**\"}]})]})]})}function m(t={}){let{wrapper:e}=t.components||{};return e?(0,n.jsx)(e,{...t,children:(0,n.jsx)(u,{...t})}):u(t)}function r(t,e){throw new Error(\"Expected \"+(e?\"component\":\"object\")+\" `\"+t+\"` to be defined: you likely forgot to import, pass, or provide it.\")}return S(v);})();\n;return Component;"},"_id":"docs/lakehouse/external-catalogs/mongodb.mdx","_raw":{"sourceFilePath":"docs/lakehouse/external-catalogs/mongodb.mdx","sourceFileName":"mongodb.mdx","sourceFileDir":"docs/lakehouse/external-catalogs","contentType":"mdx","flattenedPath":"docs/lakehouse/external-catalogs/mongodb"},"type":"Docs","path":"/lakehouse/external-catalogs/mongodb","level":3,"parent":"lakehouse/external-catalogs"}