# Duplicate emails when searching Contacts

**URL:** <https://forum.wixstudio.com/t/duplicate-emails-when-searching-contacts/57980>\
**Category:** Ask the community\
**Tags:** wix-members-backend, wix-members-area, code, cms, wix-stores\
**Created:** [April 9, 2024, 9:21am UTC](https://forum.wixstudio.com/t/duplicate-emails-when-searching-contacts/57980 "2024-04-09T09:21:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![CCorres](https://avatars.discourse-cdn.com/v4/letter/c/cc9497/32.png) [@CCorres](https://forum.wixstudio.com/u/CCorres)\
**Post date:** [April 9, 2024, 9:21am UTC](https://forum.wixstudio.com/t/duplicate-emails-when-searching-contacts/57980/1 "2024-04-09T09:21:11Z")

</div>

Found a problem with this code, which finds a contact’s unique ID based on an email. It works fine until two or more contacts share the same email on file, which I believe is permitted in the case of contacts but not site members.

So I either need to find a way to sort which is the correct user in the case of a duplicate email, or query a different email field altogether. But where is the data for “info.emails.email” stored? CMS/Full Data only shows the login emails of site members; is there a separate CMS collection for contacts?

I also looked in the Contacts section of Dashboard but the two contacts that show up as duplicates in the email query appear there with separate emails. I couldn’t see any hidden email fields or fields for a contact’s alternate/secondary email. In fact, no sign of any duplicate email until I run the code.

```js
const queryResults = await contacts.queryContacts()
    .eq('info.emails.email', emailToFind)
    .find ({suppressAuth: true});
  const contactsWithEmail = queryResults.items;

  if (contactsWithEmail.length >= 1) {
    contactID = contactsWithEmail[0]._id;
    console.log('Found contact info for client: ' + emailToFind + " " + contactID);
  } else {
     // Handle when no contacts are found
  }

```

---

<div class="post-metadata">

**Author:** ![anthony](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/anthony/32/79536_2.png) [@anthony](https://forum.wixstudio.com/u/anthony)\
**Post date:** [April 10, 2024, 6:39pm UTC](https://forum.wixstudio.com/t/duplicate-emails-when-searching-contacts/57980/2 "2024-04-10T18:39:58Z")

</div>

The `queryResults` will contain an array of `items` that each have a`.info.emails` property which is an array with all the matching contact’s emails (up to 50 emails). You can then use these results to determine all of the returned contact’s emails and deduplicate as needed.

The code as currently written only handles the first item in the array of `items` (ie. `item[0]`).

Can read more here: [https://www.wix.com/velo/reference/wix-crm-backend/contacts/contactsqueryresult/items](https://www.wix.com/velo/reference/wix-crm-backend/contacts/contactsqueryresult/items)

---

<div class="post-metadata">

**Author:** ![CCorres](https://avatars.discourse-cdn.com/v4/letter/c/cc9497/32.png) [@CCorres](https://forum.wixstudio.com/u/CCorres)\
**Post date:** [April 12, 2024, 11:54am UTC](https://forum.wixstudio.com/t/duplicate-emails-when-searching-contacts/57980/3 "2024-04-12T11:54:38Z")

</div>

Thanks. I realize the array of items is not actually the emails, but rather the unique ID of all contacts linked to the email queried, some as primary and others as alternate emails.

In my case, the query was returning the IDs of contacts on file with the queried email as an alternate email, and the Triggered email ended up not being sent to the email that was queried, but rather the primary email of a contact who had listed the queried email as an alternate.

If Triggered emails only sends the email to the “primary” email of the contact ID supplied then instead of querying .info.emails would it not be better to query primaryInfo.emails ?

Alternatively, how can you send a Triggered email to a specific alternate email?
