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

Passing "Human" as model name creates the collection as "Humen" #13037

Closed
2 tasks done
ahmetselimkaraca opened this issue Feb 15, 2023 · 3 comments · Fixed by vkarpov15/mongoose-legacy-pluralize#2
Closed
2 tasks done

Comments

@ahmetselimkaraca
Copy link

ahmetselimkaraca commented Feb 15, 2023

Prerequisites

  • I have searched existing issues to ensure the bug has not already been reported

  • I have written a descriptive issue title

Mongoose version

6.9.1

Node.js version

18.13.0

MongoDB server version

6.0.4

Typescript version (if applicable)

No response

Description

When pluralizing the collection name, mongoose sets it to "Humen". Plural for human is not humen, it's not a real word. The correct plural form is "Humans".

Steps to Reproduce

Simply naming passing "Human" to the model function results in this bug. (const Human = mongoose.model("Human", humanSchema);).

Expected Behavior

Should be set to "Humans" instead.

@Uzlopak
Copy link
Collaborator

Uzlopak commented Feb 15, 2023

Political Correct would be people. ;)
Tbh. It was bad to integrate pluralization into mongoose the first place. You can override the collectionname in the model confuguration.

@IslandRhythms IslandRhythms added the confirmed-bug We've confirmed this is a bug in Mongoose and will fix it. label Feb 15, 2023
@IslandRhythms
Copy link
Collaborator

const mongoose = require('mongoose');

const testSchema = new mongoose.Schema({
  name: String
});

const Human = mongoose.model('Human', testSchema);

async function run() {
  await mongoose.connect('mongodb://localhost:27017');
  await mongoose.connection.dropDatabase();

  const collections = mongoose.connection.collections;
  Object.keys(collections).forEach(entry => {
    console.log(entry);
    console.log(mongoose.connection.collections[entry].name)
  });
}

run();

@Uzlopak
Copy link
Collaborator

Uzlopak commented Feb 15, 2023

We can only fix pluralization issues with major version bump.

@vkarpov15 vkarpov15 added this to the 7.0 milestone Feb 17, 2023
@vkarpov15 vkarpov15 added backwards-breaking and removed confirmed-bug We've confirmed this is a bug in Mongoose and will fix it. labels Feb 17, 2023
vkarpov15 added a commit to vkarpov15/mongoose-legacy-pluralize that referenced this issue Feb 17, 2023
vkarpov15 added a commit to vkarpov15/mongoose-legacy-pluralize that referenced this issue Feb 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants