-
-
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
Use mongodb exported bson instead of mongoose to import bson separately? #15154
Comments
Mongoose imports bson directly rather than going through We do try to keep the exact same version of bson as the MongoDB driver, so most package managers should automatically share the bson version between Mongoose and MongoDB. Can you please run |
We do try to keep the exact same version of bson as the MongoDB driver, so most package managers should automatically share the bson version between Mongoose and MongoDB. I understand this, but if you use pnpm, the result is different. pnpm doesn't raise the dependencies to the top level with npm/yarn, it's still in the node_modules of the dependencies, so there's a lot of copies of different versions of bson, and since pnpm is getting more and more popular, and I'm using pnpm for my project, I just found this out. The memory footprint under pnpm is still noticeable. I think there are two ways to deal with the problem you mentioned about the browser not working: Not sure about your comments and suggestions? |
Option (1) is tricky because Webpack will pull in whatever we What we could do is move all type imports into the driver layer, so In the meantime, have you considered just using |
You are right. It looks like the only way to deal with this is from a code isolation point of view. Separate the browser from the node.js entry code or places that need to use bson, make sure that node.js references mongodb.bson, and the browser only references the bson library, so that even if mongoose installs bson separately in the node.js environment, it won't reference it. On a side note:
|
Prerequisites
🚀 Feature Proposal
When using chrome's memory to do a snapshot analysis of node.js references, I found that the bson library takes up a lot of memory, about 3-4M (estimated), especially if the project may reference multiple bson libraries.
I see that mongodb already has an API for exporting bson, so why does mongoose have to reference bson separately?
If I use mongodb's bson, then I can reference a mongoose, and I don't need to bring in mongodb and its dependent bson libraries.
It would be more memory efficient.
Motivation
No response
Example
No response
The text was updated successfully, but these errors were encountered: