Correct way of using Mongoose in Deno

Viewed 1739

In the previous project, I'm using NodeJS with Mongoose to handle schema and db connection, now that I'm trying to migrate to Deno, I found that Deno doesn't have Mongoose yet as its third party module.

I saw the reference, seems like they are using NPM to add mongoose (which means back to NodeJS way). The schema I found from deno_mongo is different from the schema I used in prev project.

And there is no example on how to use other collection id as reference to the current collection, for example:

userprofileid: {
   type: mongoose.Types.ObjectId,
   ref: "user_profiles"
},

so how to convert the code above?

2 Answers

Mongoose does not currently support Deno. See the answers in this feature request: https://github.com/Automattic/mongoose/issues/9056.
As described there, the problem is currently is that Deno bugs out with the require_optional npm module, which is something that the MongoDB driver uses internally.

The second Problem:

Even without require_optional, Deno currently doesn't have a polyfill for Node's crypto module: https://deno.land/std/node/README.md . That's going to be hard for the MongoDB driver to work around.

look like it has been solved. Especially because there are already modules for MongoDB connection.

If you can do without the ODM from Mongoose, then you can use Deno Mongo (https://github.com/denodrivers/deno_mongo). This connects you to the database and you can send your queries directly with Mongo database commands.

If you look at the third party modules on the Deno page and search for Mongo, you will unfortunately find that there is currently no ODM module for Mongo DB (https://deno.land/x?query=mongo)

Related