Created
February 9, 2021 16:23
-
-
Save gask/cb1d3dfa25b31d3ef0a406a2a12724a0 to your computer and use it in GitHub Desktop.
Repro script mongoose issue #9909
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const mongoose = require('mongoose'); | |
mongoose.set('debug', true); | |
const connectionString = ``; | |
const { Schema } = mongoose; | |
run().then(() => console.log('done')).catch(error => console.error(error.stack)); | |
async function run() { | |
await mongoose.connect(connectionString); | |
await mongoose.connection.dropDatabase(); | |
const thingSchema = new Schema({ | |
name: { | |
type: String, | |
}, | |
bookings: [{ | |
attests: [{ | |
user: {type:String}, | |
attest: {type:Boolean}, | |
comment: {type:String} | |
}], | |
ratings: [{ | |
user: {type:String}, | |
rate: {type:Number}, | |
comment: {type:String} | |
}], | |
cost: {type:Number}, | |
booking: {type:String} | |
}], | |
role: { | |
required: true, | |
type: String, | |
}, | |
joinedAt: { | |
type: Date, | |
} | |
}); | |
const Thing = mongoose.model('Thing', thingSchema); | |
let newThing = new Thing({ | |
name:'theNewThing', | |
role: 'boss', | |
bookings: [{ | |
booking: 'tr87gew' | |
}], | |
joinedAt: new Date() | |
}); | |
try { await newThing.save() | |
}catch(e){ return console.log('error adding new thing',e) } | |
// Get every session in the db | |
let thing; | |
try { thing = await Thing.findOne({_id:newThing._id}).select('name bookings'); | |
}catch(e){ return console.log('error finding thing',e); } | |
thing.bookings[0].attests[0] = { | |
user: 'bla', | |
attest: true, | |
comment: 'kakaka' | |
} | |
try { await thing.save() | |
}catch(e){ return console.log('error adding new thing',e) } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment