0

Materials: req.body.Materials is an array of objects which is showing empty in Mongodb This is the router I have created

enter image description here This is the SCHEMA design

enter image description here This is the POSTMAN output UPDATED

This is request I am sending...

enter image description here


Except for my array of objects, I am getting output for everything. How to get the output for an array of object? how to resolve this issue?

I have already used app.use(bodyParser.json()); but still, I am not getting the array of objects(Materials)

** NOTE:** I have highlighted in the images where I am facing the issue?

7
  • Can you change Materials:{type:Array} and try?? Commented Nov 22, 2019 at 11:37
  • @subburaj i have tried that also but didn't work.moreover symbol([]) defines the same Commented Nov 22, 2019 at 11:39
  • have a look into this github.com/Automattic/mongoose/issues/3249 Commented Nov 22, 2019 at 11:44
  • I can't see, what is request body for Materials? Commented Nov 22, 2019 at 11:59
  • @GRV I think you are doing something wrong for Materials like type or value Commented Nov 22, 2019 at 12:02

1 Answer 1

1

Try to define your Schema with type prop for Materials:

...
Materials: {
    type: [{
        Particular: String,
        // also you have a typo
        Quantity: Number,
        Price: Number,
        ROG: Number,
        Amount: Number,
    }]
}
...

And another typo in your request body:

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

Nothing affected....Still getting an empty array as a response

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.