Skip to content
ArticleBeginner

Connect to a MongoDB database with Cloudflare Workers

Connect a Cloudflare Worker to MongoDB with the native Node.js driver, then use a Durable Object to keep connections warm and cut latency.

Last updated
Oct 16, 2026
Read the original

Query a movies database in MongoDB from a Worker. You start with a direct connection, then move it into a Durable Object so connections persist between requests. Hyperdrive doesn’t support MongoDB (only the PostgreSQL and MySQL wire protocols), which is why the tutorial uses this pattern.

What you’ll learn

  • Enable Node.js compatibility and add the MongoDB driver
  • Connect and query from a Worker
  • Deploy, then reuse connections with a Durable Object

Cloudflare products used

Workers, Durable Objects.

Follow the full, step-by-step tutorial in Cloudflare’s documentation.

Keep learning