We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Use this plugin broke standart descriminator modle instance toObject logic, discriminator model fields don't fall in object, but accessible by dot.
const assert = require("assert"); const mongoose = require("mongoose"); const mongoRestActions = require("mongoose-rest-actions"); mongoose.plugin(mongoRestActions); // try to comment or not const GITHUB_ISSUE = `gh6701`; const connectionString = `mongodb://localhost:27017/${GITHUB_ISSUE}`; run() .then(() => console.log("done")) .catch((error) => console.error(error.stack)); async function run() { await mongoose.connect(connectionString, { useNewUrlParser: true, useUnifiedTopology: true, }); await mongoose.connection.dropDatabase(); const membershipSchema = mongoose.Schema( { name: { type: String, required: true }, price: { type: Number, required: true }, }, { discriminatorKey: "type" } ); const subscriptionSchema = mongoose.Schema({ frequency: { type: String, required: true, }, }); const Membership = mongoose.model("Membership", membershipSchema); const Subscription = Membership.discriminator( "Subscription", subscriptionSchema ); await Subscription.create({ name: "Monthly subscription", price: 1, frequency: "month", }); const sub = await Membership.findOne({ price: 1 }); console.log(sub); // don't have frequency field assert.equal(sub.frequency, "month"); // that's ok }
Because of this it is not possible to send model-dependent field descriptor by express res.json() method
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Use this plugin broke standart descriminator modle instance toObject logic, discriminator model fields don't fall in object, but accessible by dot.
Because of this it is not possible to send model-dependent field descriptor by express res.json() method
The text was updated successfully, but these errors were encountered: