-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
[BUG] cannot update nested keys inside discrimator #11428
Labels
confirmed-bug
We've confirmed this is a bug in Mongoose and will fix it.
Milestone
Comments
another data point: if |
IslandRhythms
added
the
confirmed-bug
We've confirmed this is a bug in Mongoose and will fix it.
label
Feb 18, 2022
const mongoose = require('mongoose');
const {Schema, model} = mongoose;
const StepSchema = new Schema({ url: String }, { discriminatorKey: `type` })
const SheetReadOptionsSchema = new Schema({
location: {
id: String,
timeout: Number,
},
})
const ClickSchema = new Schema(
[StepSchema, { sheetOptions: SheetReadOptionsSchema }],
{ discriminatorKey: `type` },
)
const Step = model(`Step`, StepSchema)
Step.discriminator(`click`, ClickSchema)
async function run() {
await mongoose.connect('mongodb://localhost:27017')
await mongoose.connection.dropDatabase();
let doc = await Step.create({
type: `click`,
url: `https://google.com`,
sheetOptions: {
location: {
id: `currentCell`,
timeout: 1000,
},
},
})
doc.set({
'sheetOptions.location.id': `inColumn`,
'sheetOptions.location.timeout': 2000,
})
console.log('the doc', doc)
await doc.save()
const updatedDoc = await Step.findOne({ type: `click`, _id: doc._id })
console.log(updatedDoc.sheetOptions.location.id) // `currentCell` instead of `inColumn`
console.log(updatedDoc.sheetOptions.location.timeout) // 2000 correct
}
run(); |
thanks @vkarpov15 and @IslandRhythms |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Do you want to request a feature or report a bug?
bug
What is the current behavior?
One of my keys is not updated while the other one is. It looks like Mongoose stripped away the prop while calling Mongo
If the current behavior is a bug, please provide the steps to reproduce.
What is the expected behavior?
updatedDoc.sheetOptions.location.id
should displayinColumn
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
mongoose 6.2.1
node 16.14.0
mongo 5
The text was updated successfully, but these errors were encountered: