跳到正文
文章入门

用 Cloudflare Workers 连接 MongoDB 数据库

使用原生 Node.js 驱动让 Cloudflare Worker 连接 MongoDB,再借助 Durable Object 复用连接、降低延迟。

最近更新
2026年10月16日
阅读原文

该介绍目前仅提供英文版本。

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.

继续学习