0

Am working on nestjs and i want to fetch data from the collection on the basis of 'name' value.But i got output like this:

enter image description here

code of services:

async find_one(name):Promise<Usersinterface>{
    const data=this.usersmodel.find(name).exec()
    return data;
}

code of controller:

@Get('getitem')
async getitem(@Body()name):Promise<any>{
    return this.usersService.find_one(name)
}

1 Answer 1

1

you should pass an object as a filter to the find method

so in the service, the query should look something like

find({ name: name })

the key (the first name) is the name of the property in your collection

the value (the second name) is the value you passed to the function

async find_one(name):Promise<Usersinterface> {
    const data = this.usersmodel.find({ name: name }).exec()
    return data;
}

hope it helps

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.