Hey guys,
I want to make the query createIfNotExists using the MongoDB but focused in performance because this query will be executed thousands of time in the small period of time.
So, I tried to make this query using the updateOne, but it’s updating, and I don’t want to update, I just want to create If not exists
Metricas.updateOne(
{
$or: [
{
tipo_metrica_id,
webinar_id,
ip
},
{
'participante.participante_id': participante?.participante_id,
tipo_metrica_id,
webinar_id
}
]
},
{
$set: {
participante,
tipo_metrica_id,
webinar_id,
ip,
criado_em: new Date()
}
},
{ upsert: true },
);
So, I want to create a register if these fields
{
tipo_metrica_id,
webinar_id,
IP
}
OR
{
'participante.participante_id': participante?.participante_id,
tipo_metrica_id,
webinar_id
}
Doesn’t exist in my database,
Thanks guys!