I define nested schema , when i fill the inputs it returns nothing and not save in Mongodb I define nested schema , when i fill the inputs it returns nothing and not save in Mongodb mongoose mongoose

I define nested schema , when i fill the inputs it returns nothing and not save in Mongodb


The problem was in defining the way of get the inputs,I must define the nested object and inside of that put the request bodies as well as I define the nested schema.

bsc:{bscEduLevel :req.body.bscEduLevel,    bscEduField :req.body.bscEduField,    bscEduInst :req.body.bscEduInst,    bscEduCity :req.body.bscEduCity,    bscEduDate :req.body.bscEduDate,    bscProposalTitle :req.body.bscProposalTitle}


Have you defined userSchema? If not, you are trying to export a schema which does not exist. Again, in case you have not defined userSchema and you want to export allEduSchema, replace the last line of your model file with this:

const EduSchema = mongoose.model("EduSchema", allEduSchema);module.exports = EduSchema;


Before you create a new user ,you need to require your "User" moongose Schema. Just like dimitris tseggenes said.

I use async function and try/catch to handle this problem.Maybe you could....

router.post("/", async (request, response) => {try {   const user  = new Users({new user's data here..... });   const  result = await user.save();    response.send(result);} catch (error) {    response.status(400).send(error);}

});

try catch could avoid some unexpected error and handle it.