Count objects in an array

I am having the document like this . Can someone help me with the query to get the count of Number along with the DocNumber.

{
“DocNumber”: “123456”,
“DocDate”:“2019-06-03”,
“Numbers”: [
{
“Number”: " 12345678901234567890123456789012"
},
{
“Number”: " 12345678901234567890123456789013"
}
]
}

{
“DocNumber”: “123457”,
“DocDate”:“2019-06-03”,
“Numbers”: [
{
“Number”: " 12345678901234567890123456789012"
},
{
“Number”: " 12345678901234567890123456789013"
}
]
}

O/P : Because both the documents has the same tokens . The count should be there in each doc retrieval .
{
DocNumber:“123456”,
“Numbers”: [
{
“Number”: " 12345678901234567890123456789012",
“Count” : “2”
},
{
“Number”: " 12345678901234567890123456789013"
“Count” : “2”
}
]

A nested subquery would permit you to iterate over the “Numbers” array in each document, getting the count of each distinct Number value. Note that the word “Number” is a reserved keyword, so must be placed inside back-ticks in your query.

Create the documents:

insert into my_bucket values ('key1',{
"DocDate": "2019-06-03",
"DocNumber": "123456",
"Numbers": [
    {
        "Number": " 12345678901234567890123456789012"
    },
    {
        "Number": " 12345678901234567890123456789013"
    }
]});

insert into my_bucket values ('key2',{
"DocDate": "2019-06-03",
"DocNumber": "123457",
"Numbers": [
    {
        "Number": " 12345678901234567890123456789012"
    },
    {
        "Number": " 12345678901234567890123456789013"
    }
]});

Query:

  select DocNumber, 
   (select sub.`Number`, count(*) as count from m.Numbers sub group by sub.`Number`) as counts 
  from my_bucket m

Result:

[
  {
    "DocNumber": "123456",
    "counts": [
      {
        "count": 1,
        "Number": " 12345678901234567890123456789013"
      },
      {
        "count": 1,
        "Number": " 12345678901234567890123456789012"
      }
    ]
  },
  {
    "DocNumber": "123457",
    "counts": [
      {
        "count": 1,
        "Number": " 12345678901234567890123456789013"
      },
      {
        "count": 1,
        "Number": " 12345678901234567890123456789012"
      }
    ]
  }
]

The count in both the document should be 2 as both numbers repeated in each document.

Example : 12345678901234567890123456789013 is present in 123456 document and 123457 document . So the count should be 2 in each document

Can you explain why you want to show the DocNumber if you also want the number of occurrences of each Number across all documents?

To get the global occurrence count for each Number, you can use UNNEST, e.g.,

select count(*) as count, `Number` from
  (select Numbers.`Number` from my_bucket unnest Numbers) n
group by `Number`;

This gives the following result:

[
  {
   "Number": " 12345678901234567890123456789012",
   "count": 2
  },
 {
   "Number": " 12345678901234567890123456789013",
   "count": 2
 }
]

Thanks @eben and this is what exactly I am looking for . It fits to the solution .