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 (/mod.ts | plugin_prepare@v0.6.0 | Deno)
at prepare (/mod.ts | plugin_prepare@v0.6.0 | Deno)
at async init (/ts/util.ts | mongo@v0.6.0 | 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: