denodrivers / mongo

🍃 MongoDB driver for Deno 🦕
https://deno.land/x/mongo
MIT License
509 stars 96 forks source link

Should we deprecate this module since importing with `npm:mongodb` is working well with Deno? #380

Open erfanium opened 1 year ago

erfanium commented 1 year ago

npm:mongodb pros:

cons:

lucsoft commented 1 year ago

I would love a hybrid version were we would use npm as a default but also webify the interfaces nodejs brings

erfanium commented 1 year ago

We can publish a new module on npm like mongodb-webified. It can benfites both worlds

steverandy commented 1 year ago

Can you share how did you get the npm:mongodb to work?

I got similar error to this issue: https://github.com/denoland/deno/issues/15798 when I tried using npm:mongodb in a fresh project. error: Uncaught (in promise) Error: Cannot find module 'crypto'

erfanium commented 1 year ago
import { MongoClient } from "npm:mongodb";

const client = new MongoClient("mongodb://localhost:27017/test");
await client.connect();
console.log("Connected");

console.log(await client.db().collection("test").findOne());

cmd:

deno run -A --unstable main.ts

deno 1.25.4

steverandy commented 1 year ago

Interesting. When I tried the script above it works.

But when tried using it in fresh app, I got the following error:

error: Uncaught (in promise) Error: Cannot find module 'crypto'
Require stack:
- /Users/steve/Library/Caches/deno/npm/registry.npmjs.org/mongodb/4.10.0/lib/operations/add_user.js
- /Users/steve/Library/Caches/deno/npm/registry.npmjs.org/mongodb/4.10.0/lib/admin.js
- /Users/steve/Library/Caches/deno/npm/registry.npmjs.org/mongodb/4.10.0/lib/index.js
- /Users/steve/Library/Caches/deno/npm/registry.npmjs.org/mongodb/4.10.0/lib/index.js
    at Function.Module._resolveFilename (deno:ext/node/02_require.js:615:17)
    at Function.Module._load (deno:ext/node/02_require.js:447:29)
    at Module.require (deno:ext/node/02_require.js:658:21)
    at require (deno:ext/node/02_require.js:789:18)
    at Object.<anonymous> (file:///Users/steve/Library/Caches/deno/npm/registry.npmjs.org/mongodb/4.10.0/lib/operations/add_user.js:4:16)
    at Object.<anonymous> (file:///Users/steve/Library/Caches/deno/npm/registry.npmjs.org/mongodb/4.10.0/lib/operations/add_user.js:73:4)
    at Module._compile (deno:ext/node/02_require.js:719:36)
    at Object.Module._extensions..js (deno:ext/node/02_require.js:752:12)
    at Module.load (deno:ext/node/02_require.js:636:34)
    at Function.Module._load (deno:ext/node/02_require.js:493:14)
erfanium commented 1 year ago

@steverandy please report it on fresh github repo. Thanks Not related to this issue

lucsoft commented 1 year ago

We can publish a new module on npm like mongodb-webified. It can benfites both worlds

i prefer that it stays here. Else people could be thinking that it's not really made for Deno.

josephrocca commented 1 year ago

I just tried the npm: version (v4.11.0 with Deno v1.27.0) and it for some reason it hung 90% of the time and never connected (no error thrown).

const client = new MongoClient(`mongodb://${user}:${pass}@${ip}:${port}/${dbName}`);
await client.connect();
db = client.db(dbName);

Strange that it works sometimes. Seems premature to deprecate this unless I'm making some sort of weird mistake there, but that seems like a good idea in the long run - if only to have consistency of the API between Node and Deno.

Edit: Just tested with npm:mongodb@5.7.0 and it seems to work fine now.

vorticalbox commented 1 year ago

You can follow the issues with mongoose/mongodb with deno here

https://github.com/denoland/deno/issues/15824

jtoppine commented 1 year ago

Well, since this issue is in question format, might as well give my 2 cents.

It would be sad to see "native" deno mongo driver go, or fall into disrepair. Deno driver has the potential to be cleaner, prettier and faster, and the npm compatibility layer is big, complex and slow-ish to load.

It seems to also be true that there is a lack of maintainers to keep working on the Deno driver. And that it needs nontrivial amount of work to be good enough for widespread production use. Since the userbase is small for now, and the node driver is usable already as-is, it may be unrewarding to work on the Deno driver.

Maybe the best solution for now would be to put a big banner on the readme, with:

This way regular users would not be discouraged from using Deno because of frustrating problems with unstable drivers. And there would be hope for the project to gain maintainers in the future, or even some "official" support from Mongo, eventually improving the driver beyond the NPM driver :)

ThePotatoChronicler commented 1 year ago

@erfanium The compatibility is not quite there yet: https://github.com/denoland/deno/issues/16633

denizdogan commented 10 months ago

@erfanium The compatibility is not quite there yet: denoland/deno#16633

This has supposedly been fixed in Deno 1.37!

fro-profesional commented 10 months ago

I jus tried on local an deploy and seems to be working with MongoDB Atlas serverless deno v1.37

import { MongoClient } from "npm:mongodb"
import { ulid } from "https://deno.land/std@0.202.0/ulid/mod.ts";

const client = new MongoClient("<url>")

client.connect();

Deno.serve(async () => {

  const data = await client.db("deno").collection("deno").insertOne({
    name: ulid()
  })

  return new Response(JSON.stringify({
    data
  }), {
    headers: { "Content-Type": "application/json" },
  })
})
alexbevi commented 9 months ago

Hey all, just wanted to chime in here as I'm the Product Manager at MongoDB for the Node.js driver, as well as the reporter of https://github.com/denoland/deno/issues/16633 (which was addressed directly in the driver, as well as in the runtime via https://github.com/denoland/deno/pull/20314).

Ultimately the goal is to have an ideal, runtime agnostic driver that the community can use so if there are still issues with using the driver via Deno I'd love to hear them :)

lucsoft commented 9 months ago

@alexbevi Would be cool if the Node.js driver would be Webified and uses modern standard. Same as what happened with BSON which is almost Node.js free which is awesome. My dream would be that the deno/nodejs driver could be the same code and only need to polyfill the Direct Sockets API :D (and maybe in the future not even that)

alexbevi commented 9 months ago

Thanks for the feedback @lucsoft. We're currently evaluating the driver against Deno to see if there's anything that outright doesn't work (feel free to share if you're aware of features that don't work)

erfanium commented 9 months ago

@alexbevi Thanks for reaching out to us! As far as I know, MongoDB's official driver for Node.js only ships with CJS modules. So, you'd need to use Deno's npm compatibility layer to use the official driver.

I'd love to see MongoDB's official driver shipped as a Deno-native package in the deno.land/x registry, just like this module. with no dependency to std/node