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

insertMany does not respect discriminator when using optional key #7851

Closed
thernstig opened this issue May 28, 2019 · 3 comments
Closed

insertMany does not respect discriminator when using optional key #7851

thernstig opened this issue May 28, 2019 · 3 comments
Milestone

Comments

@thernstig
Copy link

thernstig commented May 28, 2019

Do you want to request a feature or report a bug?
bug

What is the current behavior?
When using a discriminator child model with the third argument (the optional key), it is then not possible to do a parent.insertMany with discriminator value set to the same as the optional key. It will instead create the document against the parent schema only, dropping the other properties.

If the current behavior is a bug, please provide the steps to reproduce.
Consider that kind is a discriminator key. The kind will not be respected when having set 'child' as the optional key.

await Test.insertMany([
    {
        title: 'Title 1',
        __t: 'child',
        label: 'label 1'
    }
]);

const TestChild= Test.discriminator(
  'TestChild',
  testChildSchema,
  'child'
);

What is the expected behavior?
For the child schema properties/values to be inserted into the created document(s)

What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
Moongose 5.5.2
Mongodb 3.6.3
Node.js 10.13.0

@thernstig
Copy link
Author

Actually it does not seem to work for a normal const parent = new Parent() followed by parent.save() either.

@thernstig
Copy link
Author

Oh and most likely a separate issue, but https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/mongoose/index.d.ts does not account for the third parameter to discriminator()

@vkarpov15 vkarpov15 added this to the 5.5.13 milestone Jun 3, 2019
@vkarpov15 vkarpov15 added the has repro script There is a repro script, the Mongoose devs need to confirm that it reproduces the issue label Jun 3, 2019
@vkarpov15
Copy link
Collaborator

Thanks for reporting, will investigate.

We do not support @types/mongoose, so you'll have to open up an issue on DefinitelyTyped for that.

@vkarpov15 vkarpov15 removed the has repro script There is a repro script, the Mongoose devs need to confirm that it reproduces the issue label Jun 4, 2019
vkarpov15 added a commit that referenced this issue Jun 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants