I'm a newbie to the typescript, here I'm trying to update the mongo data based on pre-fetched data, in the console I'm getting all the data, but when I try to get the single key value getting an error of Property 'overallTotalMarks' does not exist on type
here below is a code what i tried
const preExams = await this.examHistoryModel.find({userId:examHistoryData.userId});
console.log(preExams) //this printing all the data in preExams
if(preExams.length <= 0){
const newHistory = new this.examHistoryModel(examHistoryData)
const result = await newHistory.save()
return result
}
else{
console.log(preExams.overallTotalMarks) //getting error on this line
return "You have attempted the test already!";
}
here is the mongo schema
export type ExamHistoryDocument = ExamHistory & Document;
@Schema()
export class ExamHistory{
@Prop({required: true})
userId?: number;
@Prop({required: true})
overAllTime: Number;
@Prop({required: true, default:0})
overallTotalMarks: Number;
@Prop({required: true, default:0})
overallGainedMarks: Number;
@Prop({required: true, default:0})
overallCorrectAns: Number;
@Prop({required: true, default:0})
overallWrongAns: Number;
@Prop({required: true, default:0})
overallLeftQue: Number;
@Prop({required: true, default:'Fail'})
overallStatus: String;
@Prop({type:[SectionHistorySchema]})
sectionHistory: SectionHistory[];
}
export const examHistorySchema = SchemaFactory.createForClass(ExamHistory)
any help or suggestions are really appriciated