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
Find query fails with an error when using discriminator key multiple times #13906
Closed
2 tasks done
Labels
confirmed-bug
We've confirmed this is a bug in Mongoose and will fix it.
Milestone
Comments
jpl-ivengi
changed the title
Find query error when using discriminator key multiple times
Find query fails with an error when using discriminator key multiple times
Sep 29, 2023
vkarpov15
added
the
has repro script
There is a repro script, the Mongoose devs need to confirm that it reproduces the issue
label
Oct 1, 2023
IslandRhythms
added
confirmed-bug
We've confirmed this is a bug in Mongoose and will fix it.
and removed
has repro script
There is a repro script, the Mongoose devs need to confirm that it reproduces the issue
labels
Oct 2, 2023
const mongoose = require('mongoose');
const { Schema } = mongoose;
async function run() {
await mongoose.connect('mongodb://127.0.0.1:27017');
await mongoose.connection.dropDatabase();
const options = { discriminatorKey: 'type' };
const eventSchema = new Schema({date: Schema.Types.Date}, options);
const Event = mongoose.model('Event', eventSchema, );
const clickedLinkEventSchema = new Schema({ url: String }, options);
const ClickedLinkEvent = Event.discriminator('ClickedLinkEvent', clickedLinkEventSchema, 'clickedLinkEvent');
const clickedImageEventSchema = new Schema({ image: String}, options);
const ClickedImageEvent = Event.discriminator('ClickedImageEvent', clickedImageEventSchema, 'clickedImageEvent');
const clickedLinkEvent = new ClickedLinkEvent({ url: 'https://clicked-link.com' });
console.log(clickedLinkEvent.type === 'clickedLinkEvent')
// expect(clickedLinkEvent.type).to.equal('clickedLinkEvent');
console.log(clickedLinkEvent.url === 'https://clicked-link.com')
// expect(clickedLinkEvent.url).to.equal('https://clicked-link.com');
const clickedImageEvent = new ClickedImageEvent({ image: 'clicked-image.png'});
console.log(clickedImageEvent.type == 'clickedImageEvent')
// expect(clickedImageEvent.type).to.equal('clickedImageEvent');
console.log(clickedImageEvent.image == 'clicked-image.png')
// expect(clickedImageEvent.image).to.equal('clicked-image.png');
const query = {
type: 'clickedLinkEvent',
$or: [
{ type: 'clickedImageEvent' }
]
}
const result = await Event.find(query).exec();
console.log(result.length == 0);
// expect(result.length).to.equal(0);
}
run(); |
vkarpov15
added a commit
that referenced
this issue
Oct 5, 2023
Island rhythms/gh 13906 handle changing discrim key
KL-Dev1
pushed a commit
to ivengi/mongoose
that referenced
this issue
Oct 11, 2023
KL-Dev1
pushed a commit
to ivengi/mongoose
that referenced
this issue
Oct 11, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Prerequisites
Mongoose version
6.12.0
Node.js version
18.18.0
MongoDB server version
4.4
Typescript version (if applicable)
5.2.2
Description
A specific search query fails in mongoose when using discriminated models.
I've checked using a much older version of mongoose (v5.9.15) which does not fail.
The error generated is:
Steps to Reproduce
The below code is typescript, using jest and chai with mongoose.
Expected Behavior
This should not be a failure. The query is written a bit strange ofcourse, but it is valid and should not be a reason for an error.
The text was updated successfully, but these errors were encountered: