How to relate the new data in mongoose association table

I am working on an examination system. There are four collections in the system:
teacher collection:

var mongoose = require("mongoose");
var Schema = mongoose.Schema;
var QuestionSchema = new Schema({
  name: String, // 
  _teacher: { type: Schema.Types.ObjectId, ref: "Teacher" }, // 
  _papers: [{ type: Schema.Types.ObjectId, ref: "Paper" }], // 
  content: String, // 
  selection: [String], // 
  type: {type:String,enum:[ // 
    "single", // 
    "multi", // 
    "Q&A", // 
    "judgement" // 
  ]},
  score: Number, // 
  answer: String // 
});
module.exports = mongoose.model("Question", QuestionSchema);

in the system, teachers can add test papers, so I don"t know how to save the data sent from the front desk. There are not only information about the examination papers, but also a lot of questions in the data. All the questions belong to the test paper, and the changed paper belongs to the teacher who currently logs in to the system (that is, the teacher who created the test paper).
how can test papers, teachers, and questions be related? ref stores _ id, but these new data are saved before _ id.
this question has been bothering me for many days. I hope some god can answer it. Thank you very much!
Thank you first ~

Mar.02,2021

answer your own questions!

// 
paperForm = {
    name: ''
    total: 100
    ....
    questions: [
        {
            name: '1'
            answer: 'A'
            type: 'single',
            ...
        },
        {
            name: '2'
            answer: 'A'
            type: 'single',
            ...
        },
        ...
    ]
}
exports.savePaper = function (req, res) {
  let paperForm = req.body.paperForm;
  let userName = req.session.userName;

  // console.log(paperForm);
  // console.log(userName);
  if(paperForm == {}){
    res.json({
      status:'5',
      msg: ''
    })
  }
  Teacher.findOne({"userName": userName}, (err,doc)=>{
    if (err) {
      res.json({
        status:'1',
        msg: err.message
      })
    } else {
      if (doc) {
        let paperData = {
          name:paperForm.name,
          totalPoints:paperForm.totalPoints,
          time:paperForm.time,
          _teacher: doc._id,
          _questions: [],
          examnum:0
        }
        Paper.create(paperData,function (err1,doc1) {
          if (err1) {
            res.json({
              status:'1',
              msg: err.message
            })
          } else {
            if (doc1) {
              // console.log('doc1 paper:'+doc1._id);
              doc._papers.push(doc1._id); // 
              doc.save(); //  save
              // console.log('doc teacher'+doc._papers);
              paperForm.questions.forEach(item => {
                item._papers = [];
                item._papers.push(doc1._id);
                item._teacher = doc._id;
              })
              Question.create(paperForm.questions,function (err2,doc2) {
                if (err2) {
                  res.json({
                    status:'1',
                    msg: err.message
                  })
                } else {
                  if (doc2) {
                    // console.log('doc2 ques:'+doc2)
                    doc2.forEach(item => {
                      doc1._questions.push(item._id);
                    })
                    doc1.save(); //  save
                   res.json({
                      status:'0',
                      msg: 'success'
                    })
                  } else {
                    res.json({
                      status: '2',
                      msg:''
                    })
                  }
                }
              })
            } else {
              res.json({
                status: '2',
                msg:''
              })
            }
          }
        })
      }
      else {
        res.json({
          status: '2',
          login: false,
          msg:''
        })
      }
    }
  })
};

this is my implementation method, this is already a "callback hell", if necessary, you can use your own Promise optimization.

Menu