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

options object get mutated #13335

Closed
2 tasks done
mpodolsk opened this issue Apr 27, 2023 · 0 comments · Fixed by #13376
Closed
2 tasks done

options object get mutated #13335

mpodolsk opened this issue Apr 27, 2023 · 0 comments · Fixed by #13376
Labels
developer-experience This issue improves error messages, debugging, or reporting
Milestone

Comments

@mpodolsk
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

7.0.3

Node.js version

18.15.0

MongoDB server version

5.0

Typescript version (if applicable)

No response

Description

when creating mongo connection we pass a connection string and options object
in this case the options object gets mutated
My code is taking options from node-config which properties make it immutable. This results in crash when mongoose is trying to mutate the passed object.

mpodolsk$ node bug.mjs
/node_modules/mongoose/lib/helpers/processConnectionOptions.js:49
  opts.config = { autoIndex: false };
              ^

TypeError: Cannot add property config, object is not extensible

Steps to Reproduce

import mongoose from "mongoose";
const opts = Object.preventExtensions({});
await mongoose.connect('mongodb+srv://x:pass@somehost.com/db?retryWrites=true&w=majority&readPreference=secondaryPreferred', opts);

Expected Behavior

it copies the properties needed and uses them without modding the passed object

@vkarpov15 vkarpov15 added this to the 7.1.1 milestone May 1, 2023
@vkarpov15 vkarpov15 added the developer-experience This issue improves error messages, debugging, or reporting label May 1, 2023
@vkarpov15 vkarpov15 removed their assignment May 2, 2023
vkarpov15 added a commit that referenced this issue May 4, 2023
fix: don't modify passed options object
vkarpov15 added a commit that referenced this issue Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
developer-experience This issue improves error messages, debugging, or reporting
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants