DEV Community

Adrian Fathan
Adrian Fathan

Posted on

Using MongoDB with Cloudflare Workers

When I tried to create a simple project using Cloudflare Workers and MongoDB, I encountered multiple errors that made the integration process difficult. During my research, I found a few articles that discussed the compatibility issues between MongoDB and Cloudflare Workers.

  1. MongoDB and Cloudflare Workers Compatibility Issues I discovered an article titled "MongoDB Can't Integrate with Cloudflare Workers" that highlighted the limitations of using MongoDB with Cloudflare Workers directly. This is primarily due to the Workers' environment, which restricts the use of certain Node.js modules and native MongoDB drivers.

  2. Official MongoDB Atlas Data API MongoDB provides an alternative with the Atlas Data API, as described in the article "Create a REST API with Cloudflare Workers and MongoDB Atlas." This approach uses RESTful API calls to interact with MongoDB Atlas, bypassing the need for native drivers that don't work in the Cloudflare Workers environment.

My Solution: A TypeScript SDK for MongoDB Atlas Data API

To overcome the integration challenges, I developed an NPM package that simplifies the process. This package is a TypeScript SDK that acts as a wrapper for the MongoDB Atlas Data API, providing type safety and full IntelliSense support for query operators.

masfana-mongodb-api-sdk - npm (npmjs.com)

Top comments (1)

Collapse
 
henkdz profile image
HenkDz

Thanks, MongoDB are deprecating Atlas Data API and have removed their docs about Cloudflare Workers.
mongodb.com/docs/atlas/app-service...