RunJS
RunJS copied to clipboard
Caching problem?
I'm not sure what makes this situation, but I'm not able to run the code anymore. It keeps throwing an error whenever I run the code below:
const mongoose = require('mongoose')
const UndefinedTest = mongoose.model('UndefinedTest', new mongoose.Schema({
name: String,
job: String,
family: {
name: String,
age: Number
},
}));
(() => {
mongoose.connect('mongodb://localhost/dev', {
useNewUrlParser: true
}, async (err) => {
const db = mongoose.connection
await UndefinedTest.deleteMany({})
const saveData = {
name: 'Reid',
job: undefined,
family: {
name: undefined,
age: 17
}
}
await new UndefinedTest(saveData).save()
const saveDoc = await UndefinedTest.find({ name: 'Reid' }).lean()
console.log('Create a document with undefined fiels')
console.table(saveDoc)
const updateData = {
job: undefined,
family: {
name: undefined,
age: 27
}
}
await UndefinedTest.findOneAndUpdate({ name: 'Reid' }, { $set: updateData })
const updateDoc = await UndefinedTest.find({ name: 'Reid' }).lean()
console.log('Update the document with undefined fiels')
console.table(updateDoc)
await db.close()
})
})()
OverwriteModelError: Cannot overwrite `UndefinedTest` model once compiled.
I know this error is from mongoose, and it's caused by multiple instantiations of a model. but as you can see, I didn't initilaize twice. I've tried to restart Run.js but it doesn't make change.
I'll take a look into this. For now, you might find that turning on the 'Holistic evaluation' option in the advanced settings may improve the handling of this.
This is now resolved in version 1.5.0