How to properly organize a Mongo structure

Advise how to properly organize the data storage structure in Mongo. Input data E-mail, phone number and a unique number of the site visitor are stored in a cookie and, accordingly, may change for various reasons (n_id). Let’s say I receive n_id and phone number. I’m creating a Document. The second time I get n_id and email. I need to check, by E-mail and n_id, there is such a document that contains either this or that. If there is, then supplement it with the missing data. That is, 1 document can have 2 numbers, 10 n_id, and 5 email. When I thought 2 storage structures, maybe you can advise how best.
1.Variant
{
“_id”:

 {"$oid": "5f56a52a9eafb85d4314c612"},
"created_at": {"$date": "2020-09-07T21:24:58.766Z"},
"data": [
  {
    "phone": 77777777,
    "email": "1@1.ru",
    "n_id": 12
  },
  {
    "phone": 177777777,
    "email": "11@1.ru",
    "n_id": 112
  }
],
"updated_at": {"$date": "2020-09-07T21:24:58.766Z"}

Second option

     {"_id": {"$oid": "5f56a5ba9eafb862c7676c02"},
"created_at": {"$date": "2020-09-07T21:27:22.454Z"},
"updated_at": {"$date": "2020-09-07T21:27:22.454Z"},
"email": ["1@1.ru", "31@1.ru"],
"n_id": [12, 112],
"phone": [77777777, 3377777777]}

Hi @11188,

Thanks for sharing your use case and thoughts.

So if I understand correctly your application will keep client cookie identities comprising of a property and an n_id unique value , you will always search the user document with this 2 combinations.

I would like to suggest another alternative to not duplicate values and also search efficiently when keeping all data in one doc:


“_id”:

 {"$oid": "5f56a52a9eafb85d4314c612"},
"created_at": {"$date": "2020-09-07T21:24:58.766Z"},
"identities": [
  {
    "Identity": 77777777,
    "Type": "phone",
    "n_id": 12
  },
  {
    "Identity": 177777777,
    "Type": "phone",
    "n_id": 112
  },
  {
    "Identity": "1@1.ru",
 "Type" : "email",
    "n_id": 123
  }
],
"updated_at": {"$date": "2020-09-07T21:24:58.766Z"}

Now if the n_id is unique cross users you can index { identities.n_id : 1, identities.Identity : 1} and search them both providing the values.

This will retrieve the user and all his known identies.

Let me know what you think.

Best
Pavel