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

_id no longer recursive when another version of bson in installed #15140

Open
2 tasks done
BobBatard opened this issue Dec 31, 2024 · 9 comments
Open
2 tasks done

_id no longer recursive when another version of bson in installed #15140

BobBatard opened this issue Dec 31, 2024 · 9 comments
Labels
has repro script There is a repro script, the Mongoose devs need to confirm that it reproduces the issue
Milestone

Comments

@BobBatard
Copy link

Prerequisites

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

Mongoose version

8.9.1

Node.js version

20.7.0

MongoDB server version

8.0.1

Typescript version (if applicable)

No response

Description

I experienced something quite similar to this closed issue #14867

Following a mongoose update (8.9.1) in my project (with yarn) without any problem, for whatever reason I decided to delete the yarn.lock file to regenerate it, and encountered the issue described by @gl-aagostino
The recursiveness worked when creating an ObjectId in code, but fails when loading a document from the db

Turns out this version of mongoose uses [email protected], and [email protected] was also in my package.json
Updating bson to 6.10.1 resolved the problem

Not sure if it's a yarn, mongoose or bson issue, but couldn't find talks about this anywhere else

Steps to Reproduce

create a project with [email protected] and [email protected]
insert a doc in db and find it
doc._id._id should crash

Expected Behavior

doc._id._id should not crash

@BobBatard BobBatard changed the title _id no longer recursive when bson in installed _id no longer recursive when another version of bson in installed Dec 31, 2024
@vkarpov15
Copy link
Collaborator

Can you please provide some code samples that demonstrate this issue? doc._id._id not existing means most likely you're somehow converting a Mongoose document's [email protected] ObjectId into a [email protected] ObjectId

@vkarpov15 vkarpov15 added the needs clarification This issue doesn't have enough information to be actionable. Close after 14 days of inactivity label Jan 6, 2025
@BobBatard
Copy link
Author

BobBatard commented Jan 6, 2025

Attached is a simple project which creates a document in db, finds it, then logs doc._id._id
Only mongoose is specified in package.json

steps to reproduce the bug :

yarn install
# logs an _id
yarn start
yarn add [email protected]
# logs undefined
yarn start 
yarn add [email protected]
# logs an _id
yarn start

mongoose-bson.zip

@BobBatard BobBatard reopened this Jan 6, 2025
Copy link

This issue is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 5 days

@github-actions github-actions bot added the Stale label Jan 21, 2025
@BobBatard
Copy link
Author

@vkarpov15 do you think this is a mongoose bug ? or the issue should be closed ?

@github-actions github-actions bot removed the Stale label Jan 24, 2025
@vkarpov15 vkarpov15 added has repro script There is a repro script, the Mongoose devs need to confirm that it reproduces the issue and removed needs clarification This issue doesn't have enough information to be actionable. Close after 14 days of inactivity labels Jan 24, 2025
@vkarpov15 vkarpov15 added this to the 8.9.6 milestone Jan 24, 2025
@vkarpov15
Copy link
Collaborator

Sorry for letting this issue get stale, we'll review this next week.

@BobBatard
Copy link
Author

No problem, thanks !
Here is an updated repro script which fixes the call to model.create

mongoose-bson.zip

@vkarpov15 vkarpov15 modified the milestones: 8.9.6, 8.9.7, 8.10.1 Jan 31, 2025
@vkarpov15
Copy link
Collaborator

This issue isn't just limited to yarn, npm also similarly doesn't dedupe packages when the top-level version of bson is different. Here's my npm list output, notice no "deduped" next to [email protected]'s version of bson

$ npm list --depth=3
[email protected] /Users/val/Workspace/MongoDB/troubleshoot-mongoose/mongoose-bson
├── [email protected]
└─┬ [email protected]
  ├── [email protected]
  ├── [email protected]
  ├─┬ [email protected]
  │ ├── UNMET OPTIONAL DEPENDENCY @aws-sdk/credential-providers@^3.188.0
  │ ├─┬ @mongodb-js/[email protected]
  │ │ └── [email protected]
  │ ├── UNMET OPTIONAL DEPENDENCY @mongodb-js/zstd@^1.1.0 || ^2.0.0
  │ ├── [email protected]

With npm, npm dedupe fixes this issue. With Yarn, you should be able to do yarn dedupe bson and get the correct behavior. Can you confirm whether this fixes the issue for you?

However, you're right that this behavior is unexpected and tricky to debug. We will take a closer look at #15154, which suggests Mongoose removing bson as a top-level dependency and just depending on the MongoDB Node driver.

@BobBatard
Copy link
Author

BobBatard commented Feb 7, 2025

On the project I am working on, with npm 11.1.0, if [email protected] is already installed and I install [email protected], the application starts normally, even without using npm dedupe.

When installing [email protected] with yarn 1.22.22, the application does not start (because it tries to use an ObjectId recursively during startup).
Deleting the node_modules folder and then running yarn install again does not work either.
yarn dedupe returns this error in 1.22.22:
error The dedupe command isn't necessary. 'yarn install' will already dedupe.
Using the yarn-deduplicate module does not change anything.

In this state, running npm install fixes the issue, even without npm dedupe (the yarn.lock file is then modified by npm install).
After that, the issue no longer occurs when running yarn install again.

On the project I attached with my previous post, with npm, going back and forth between 6.10.1 and 6.1.0, _id is recursive only when installing 6.10.1 and after a npm dedupe.
With yarn I just cannot reproduce the behavior I was describing, and I'm pretty sure I was experiencing it at the time I wrote my previous post.
Now as long as bson is installed, the _id is not recursive, it works only if I uninstall bson.

I don't know what to think, I guess I'm missing something...

@vkarpov15
Copy link
Collaborator

All very strange. I think the correct solution will be #15154, but that will take some time for us to implement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has repro script There is a repro script, the Mongoose devs need to confirm that it reproduces the issue
Projects
None yet
Development

No branches or pull requests

2 participants