I’m trying to use findOne()
with mongoose DB. I’m integrating this with Discord, and I’m checking if the teamName
property was provided with one of the options for the Discord command.
Meaning teamName
can be undefined or be a string
I came up with this idea of seeing if it’s possible to check if I have the name query be the teamName
or be undefined
but if the teamName
property exist, The team isn’t found.
const team = await teams.findOne({
$and: [
{ ["owner.id"]: slash.user.id },
{ division },
{ name: teamName ? teamName : undefined },
],
});