needle
needle copied to clipboard
query : how to handle nesting in body section of post method
Hi Team,
I have started using 'needle' recently instead of 'request' module. One of the API call (to select data from database) includes complex input:
- Database model - simple string
- Database input - object or array of objects (with $or, $and operators)
For e.g.
let options = {
json: true,
model: "SampleModel",
_**input: {
$or: [
{ where_field1: 'abc' },
{ where_field2: '123' }
]
}**_
}
'request' was able to handle it properly and fetch the data. But needle gets stuck during the call.
If I pass it a simple object, like shown below, it works.
_**input: { where_field1: 'abc' }**_
How to handle it?
Issue Identified, Solution Needed
I looked at the server logs (of API which is being called):
Instead of array of two objects
{"$or":[{"requestor_id":"alice" } , { "service_provider":"alice"}]}
It is coming as array of single object, so no output.
{"or":[{"requestor_id":"alice" , "service_provider":"alice"}]}
** Input is being passed properly to the API call as I have mention in the above thread .