Is there a way to specify the argument type in a function as a string from a list of strings in order to run a MongoDB query? Here is what I am currently attempting:
users.services.ts
async findOne(key: "_id" | "email" | "username", value: string) {
const user = await this.userModel.findOne({ key: value }).exec();
if (!user) {
throw new NotFoundException();
}
return user;
}
This is how and where I am calling findOne
in users.services.ts
const user = await this.usersService.findOne("username", username);
Unfortunately, it's not working as expected and during debugging, the values of key and value are not being picked up.
Thank you in advance for any assistance provided.