GRV
GRV

Reputation: 113

Posting array of objects to mongodb, showing NULL

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?

Upvotes: 0

Views: 135

Answers (1)

zemil
zemil

Reputation: 5066

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

Upvotes: 1

Related Questions