-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cloudflare Workers support (maybe via a HTTP Driver) #14613
Comments
I'm unable to repro, the following script works fine with Node.js. Please modify the following script to demonstrate your issue. Also, can you please clarify whether you're using Next.js or some environment other than Node.js, and also which version of TypeScript you're using and your TypeScript config? I see you have an import { serve } from '@hono/node-server';
import { Hono } from 'hono';
import mongoose from 'mongoose';
const app = new Hono()
app.get('/', async (c) => {
await mongoose.connect('mongodb://127.0.0.1:27017/mongoose_test');
return c.text('Hono meets Node.js')
})
serve(app, (info) => {
console.log(`Listening on http://localhost:${info.port}`) // Listening on http://localhost:3000
}) Output:
Curl command:
|
This issue is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 5 days |
I have used for cloudflare workers (wrangler)TS version - latest |
The easiest way to fix this particular error is to add the following to your
However, with that, we still get the following errors:
I'm investigating a fix. But it's worth mentioning that we haven't tested Mongoose with Cloudflare Workers at all. |
I took some time to play whack-a-mole with all the build issues that pop up with Cloudflare Workers, but still no luck, Mongoose can't connect. It looks like Cloudflare Workers has some support for TCP sockets, but looks like that doesn't quite work with the MongoDB driver. It looks like the MongoDB driver doesn't support Cloudflare Workers, the officially supported way to connect to MongoDB from Cloudflare Workers is Realm. Mongoose doesn't have a Realm driver, so we can't quite use that yet. But we may consider adding a Realm driver in the future. |
Cloudflare doesn't support TCP protocol, there would need to be an HTTP implementation using REST API. Is this something mongoose can do, connect differently? Firebase has a J |
Yes, Mongoose can in theory use HTTP or some alternative protocol via the Driver API. |
@vkarpov15 Well Realm is deprecated soon |
In that case, we will update the issue title to remove reference to Realm: https://www.mongodb.com/products/updates/product-support-deprecation?tck=notice_product_deprecation_2024. |
@vkarpov15 Okok, so how will mongo run in cloudflare workers? |
It's not just Cloudflare, it is Vercel Edge, Deno, Bun, and other non-node environments fwi. This is the new norm. |
@jdgamble555 no mongoose doesn't work on cloudflare, but others where there's a full nodejs environment it works, e.g Vercel (not edge, vercel edge is just like cloudflare), Bun, Deno |
Right, Vercel Edge uses Cloudflare under the hood. What I'm saying is the new normal is multiple environments. Mongoose should work in ALL JavaScript environments. The only way to do this is to have on option that uses HTTP under-the-hood. This is how J |
You mean they are re-selling the cloudflare workers platform ? i thought they were using something from aws/gcp. I used the full Vercel functions (without edge) and it works. anyways mongo is cooked! without a light weight HTTP client (Realm) who ever deprecated realm shouldn't get promoted. |
We won't run MongoDB in cloudflare workers, but Mongoose's driver API makes it possible for Mongoose to speak HTTP under the hood. For example, that's how stargate-mongoose works: subs out default MongoDB driver for an HTTP-based driver that talks to DataStax's Data API. |
Hey buddies, is there any way to use MongoDB (with Mongoose) with CloudFlare Workers? |
@mohit-singh-13 as far as I know, there's no way to run Mongoose on Cloudflare Workers currently. Sorry. |
@vkarpov15 alright, thanks a lot |
Prerequisites
Mongoose version
8.4.0
Node.js version
20.11.1
MongoDB server version
7.0.8
Typescript version (if applicable)
No response
Description
i was trying to use mongodb with honojs and i have installed mongoos but
connectDB
function is showing the errorimport_mongoose.default.connect is not a function
log
Steps to Reproduce
The text was updated successfully, but these errors were encountered: