Reputation: 207
I am working on nodejs with express and in my project I require the filter as well as nested object.
If I set this middleware for bodyparser
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json('application/json'));
then filter is working properly but nested object gives undefined value
look at that in picture I search amit and i get only one record which name is amit
if I set this middleware for bodyparser
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json('application/json'));
then nested object works properly but filter gives undefined value
I search amit and I get all records.
how can I get both of value properly?
Please help
Upvotes: 0
Views: 193
Reputation: 779
When you make extended false you can't pass nested objects. The middleware is used for extracting body contents from the incoming requests. So you can do one thing, use the following code
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json('application/json'));
and extract object using dot(.) operator instead of req.body['....[...]']
for example,
req.body.search.value
works fine, but
req.body['search[value]']
may be undefined
Upvotes: 1