Mongoose sequence increment value not acessable

Viewed 18

i am using mongoose module to get a pretty id but when i assign the prettyId value and use

await student.setNext("studentId");

i can't do student.save() and i can't access student.prettyId but it's stored in the database and it's acessable anywhere but the scope where i declare student

const { password, name, classId } = req.body;


const myClass = await Class.findOne({ prettyId: classId });

  const student = new Student({
    name: name,
    password: await bcrypt.hash(password, 10),
    class: {
      id: myClass._id,
      prettyId: myClass.prettyId,
      name: myClass.name,
    },
  });
  await student.setNext("studentId");
  console.log(student.prettyId) // not working
  await student.save() // not working
0 Answers
Related