0

I am working on nestjs and I want to retrieve data from DB on the basis of name property, which I am passing in a method of services code. The issue is when am passing {"name": "item1"} in postman, am getting item1 related data, but when am passing {"name":"item1","name":"item2"} in postman, I am getting data related to item2 only.I want to retrieve data of both item1, item2, and so on. To overcome this issue I thought rest parameters would be a good choice, but I don't know how to pass rest parameters and how to call rest parameters in postman. The main problem is I don't know how to deal with rest parameters in postman and code too.

Here is the code of services:

async individual(...name:any){
    const ind= await this.usersmodel.find({'name':{$in:name}})
    return ind
}

Here is the code of controller:

@Post('ind')
async ind(@Body('name')name){
    return this.usersService.individual(name)
}

screenshot of postman: enter image description here

screenshot of error am getting by using this method: enter image description here

1 Answer 1

2

Your question isn't well formulated but i will pretend you are trying to find in your schema a number of values that you will provide trought your API.

Thinking that way, you can use a POST to sendo an Array inside your body, like that:

"name": ["item2", "item3", "item4"]

Inside your service file you receive that array and can still use find(), but that way:

await this.usersmodel.find({
'name': { $in: name }
}
Sign up to request clarification or add additional context in comments.

Comments

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.