Updating mongodb through mongoose schema

`i have a schema like thisconst Student = mongoose.model(
“students”,
new mongoose.Schema(
{
lname: {
type: String,
required:true
},
fname: {
type: String,
required:true
},
level: {
type: Number,
min: 1,
max: 7,
required:true
},
studid: {
type: String,
unique: true,
},
// terms: [{ type: mongoose.Types.ObjectId, ref: “terms” }],
terms: ,

},

)
);

Am trying to itterate an array which contains many document of type
[
{
dmark: 50,
dstatus: ‘bot’,
tname: ‘Term-2-2023’,
subname: ‘English’,
owner: ‘659b7b3a57e4cdd2af3a66a0’,
myid: ‘6’
}
]

and update my students database with marks. my student databse has records such as
{
_id: ObjectId(“659b7b3a57e4cdd2af3a66b4”),
studid: ‘26’,
fname: ‘Adoree’,
lname: ‘Georgeau’,
level: 4,
terms: [
{
tname: ‘Term-2-2023’,
substaken: [ ‘English’, ‘Mathematics’ ],
submarks: [
{ subname: ‘English’, bot: 0, eot: 0 },
{ subname: ‘Mathematics’, bot: 0, eot: 0 }
],
feespaid:
}
]
},

am trint to update all document that have submarks.English and modify either bot or eot fields through my mongo student schema as above`

Please update your post after reading Formatting code and log snippets in posts.

1 Like