TypeError: Cannot read properties of undefined (reading 'Todo')
Unanswered
Ragdoll posted this in #help-forum
RagdollOP
Even though I have defined other models same as Todo.
Unable to fix the issue.
I am creating newTodo inside
// inside helper.ts
Unable to fix the issue.
I am creating newTodo inside
helper.js which is getting called from client component - BookForm.tsimport mongoose from "mongoose";
const TodoSchema = new mongoose.Schema(
{
title: {
type: String,
required: true,
minLength: 5,
},
userId: {
type: mongoose.Schema.Types.ObjectId,
},
},
{ timestamps: true }
);
export default mongoose.models.Todo || mongoose.model("Todo", TodoSchema);// inside helper.ts
export const saveTodo = async (title: any, email: any) => {
const userId = await User.findOne({ email: email });
const newTodo = new Todo({ title, userId: userId._id });
await newTodo.save();
};