How to connect mongodb in edge-functions(deno runtime environment)?

INFO downloading deno plugin “deno_mongo” from “https://github.com/manyuanrong/deno_mongo/releases/download/v0.6.0/deno_mongo.dll
PermissionDenied: Requires write access to “.deno_plugins”, run again with the --allow-write flag
at Object.mkdir (ext:deno_fs/30_fs.js:140:14)
at download (Third Party | Deno)
at prepare (Third Party | Deno)
at async init (Third Party | Deno)

Edge Functions support npm packages, no need to use Deno-specific libraries. But FS is likely not supported in Edge Functions.

the npm package also have some problems,


the package from mongodb official

That sounds like a MongoDB problem than a Netlify one. Have you reached out to them? Does this work in Lambda functions?

I’ve tested it and it works in the lamabda function (nodejs runtime environment), it’s only in deno runtime that it appears like this

Alright. Could you package this in a repository and share that with us, so we could take a look?


I need a repo, not a screenshot.

This connects just fine for me in my Edge functions when I intended to use for Server Sent Events. Unfortunately my Edge function crashes entirely (seems to be a Deno issue) when I try to use it with a SOCKS proxy (which I need to do as I’m not exposing Mongo auth to the internet). Think I have to pull the plug on my project myself, but hopefully this helps :

import mongo from ‘mongodb’;
const { MongoClient, ServerApiVersion } = mongo;

const client = new MongoClient(fullmongoconnectionstringgoeshere, {
serverApi: {
version: ServerApiVersion.v1,
strict: true,
deprecationErrors: true,
}
});
await client.connect();
// run a ping, see it works…
await client.db(“admin”).command({ ping: 1 });

If you need help from us, you’d need to share the URL where we can reproduce this issue along with the steps required to see this problem. If this was just a comment to the above post, feel free to ignore my message.

If you’re able to invest the time into resolving a bug between Deno and how it supports the MongoDB NPM package when used with a SOCKS proxy, that would be awesome – I reproduced it and posted up the issue here:

I don’t have much faith in seeing this resolved any time soon given this is now one of 1700 open issues with Deno.

At the moment this issue is going to force me off of Netlify which I’ve loved for many years - I have some long-running functions I need to run that are MongoDB-intensive (building HTTP proxy endpoints for Mongodb is a non-starter) :frowning:

If this is a Deno limitation, I don’t believe there’s much that can be done from our end until Deno solves this problem.

Is there any news on this? MongoDB has a tutorial post on how to connect using Demo 2.0. So, I believe Demo 2.0 already supports MongoDB NodeJs deriver, but the Netlify Deno runtime doesn’t. Could you please provide some guidance on this?

We’re in the process of upgrading to Deno 2.0 and the rollout has already begun. This should be possible in the upcoming weeks or maybe in a month or two.

Thank you for the update @hrishikesh. How can I get the news once it’s rolled out?

I believe we’d post on our blog about this change. You might also see this in the UI notifications. Even netlify-cli would be updated to start using Deno 2.0.

1 Like

@hrishikesh :waving_hand:, Any updates on this ?

We’re starting a slow rollout of Deno 2.0 in our build systems. If all goes well, it should be rolled out to everyone in the coming weeks.

1 Like

That’s a great news @hrishikesh. Thank you :folded_hands: