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

How can I use collection as schema property name? #13956

Closed
1 task done
LvChengbin opened this issue Oct 9, 2023 · 1 comment · Fixed by #13968
Closed
1 task done

How can I use collection as schema property name? #13956

LvChengbin opened this issue Oct 9, 2023 · 1 comment · Fixed by #13968
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Milestone

Comments

@LvChengbin
Copy link

Prerequisites

  • I have written a descriptive issue title

Mongoose version

7.6.0

Node.js version

19.4.0

MongoDB version

7.0

Operating system

macOS

Operating system version (i.e. 20.04, 11.3, 10)

No response

Issue

After doing lots of research, I still can't understand how I can use collection as property name in schema because it's a reserved key.

{
    collection : { type : String, required : true }
}
@LvChengbin LvChengbin added help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary help wanted labels Oct 9, 2023
@IslandRhythms
Copy link
Collaborator

From what I can see it appears that collection is a property on mongoose docs which is why you can't as it throws an error. A workaround could just be to use a shorthand or simply capitalize collection to Collection

vkarpov15 added a commit that referenced this issue Oct 11, 2023
…type.collection` to allow defining `collection` as a schema path name

Fix #13956
@vkarpov15 vkarpov15 added this to the 7.6.2 milestone Oct 11, 2023
@vkarpov15 vkarpov15 added confirmed-bug We've confirmed this is a bug in Mongoose and will fix it. and removed help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary help wanted labels Oct 11, 2023
vkarpov15 added a commit that referenced this issue Oct 13, 2023
fix(document): avoid triggering setter when initializing `Model.prototype.collection` to allow defining `collection` as a schema path name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Projects
None yet
3 participants