Skip to content
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

Open
2 tasks done
zurmokeeper opened this issue Jan 3, 2025 · 2 comments
Open
2 tasks done
Labels
discussion If you have any thoughts or comments on this issue, please share them! help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary

Comments

@zurmokeeper
Copy link

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the feature has not already been requested

🚀 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

@zurmokeeper zurmokeeper added enhancement This issue is a user-facing general improvement that doesn't fix a bug or add a new feature new feature This change adds new functionality, like a new method or class labels Jan 3, 2025
@vkarpov15
Copy link
Collaborator

Mongoose imports bson directly rather than going through mongodb.BSON is for the browser build: we haven't tried recently, but importing the MongoDB driver makes it impossible for Mongoose to run in the browser.

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 npm list bson and paste the output here? That would be helpful.

@vkarpov15 vkarpov15 added discussion If you have any thoughts or comments on this issue, please share them! help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary and removed new feature This change adds new functionality, like a new method or class enhancement This issue is a user-facing general improvement that doesn't fix a bug or add a new feature labels Jan 6, 2025
@zurmokeeper
Copy link
Author

Image

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:
1: Determine if it's a browser or node, and then load it separately.
2: I'd like to see what's causing the browser not to work, and see what I can do about it so that the browser can support it.

Not sure about your comments and suggestions?
@vkarpov15

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion If you have any thoughts or comments on this issue, please share them! help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary
Projects
None yet
Development

No branches or pull requests

2 participants