feat: agregar lógica para evitar duplicados de clientes por email y vincular usuarios existentes

This commit is contained in:
2026-10-06 11:52:24 -03:00
parent 13ba0fa4de
commit 0d6231a02e
4 changed files with 351 additions and 11 deletions
@@ -0,0 +1,8 @@
db.clients.aggregate([
{ $group: {
_id: { companyId: "$companyId", email: { $toLower: "$email" } },
count: { $sum: 1 },
emails: { $addToSet: "$email" }
} },
{ $match: { count: { $gt: 1 }, $expr: { $gt: [{ $size: "$emails" }, 1] } } }
])