My query looks like this
const result = await Form.findOne({ _id: req.params.id });
And here is the output of my query:
{ _id: 5a8ea110d7371b7e5040d5c9,
_user: 5a5c277f8d82ba3644b971c2,
formDate: 2018-02-22T10:53:04.579Z,
formElement:
{ formName: 'Vanilla Form',
pixel: '23423325',
fieldRows: [ [Object], [Object] ] },
formStyle:
{ globalColor: [ [Object], [Object], [Object] ],
elementSizing: 'medium',
elementStyle: 'radius',
fontFace: 'Open Sans',
fontSize: { label: '15', button: '15' } },
__v: 0,
status: true }
I am attempting to retrieve the pixel value like this
console.log(result.formElement.pixel)
However, when I try to access the pixel value, it returns
undefined
.What could be the issue?
Update
Here is the updated portion of my code:
app.get("/view/:id", async (req, res) => {
const result = await Form.findOne({ _id: req.params.id });
console.log(result);
console.log(result.formDate); //returns 2018-02-22T10:53:04.579Z
console.log(result.formElement.pixel); //returns undefined
// res.render("form", {
// result
// });
});
I have tried modifying my code by using Promise instead of async, but I still encounter the same issue of getting an undefined value.