0

I have a collection and object where this object has a list of objects as following:

{
"_id": {
    "$oid": "615617f5b0cd1765b7ba21c1"
},
"response": {
    "requestId": "7563381",
    "results": [
        {
            "itemCode": "45-277-98",
            "amount": 59.35,
        },
        {
            "itemCode": "8-278-04",
            "amount": 15.25,
        },
        {
            "itemCode": "39-762-12",
            "amount": 11.1,
        },
        {
            "itemCode": "39-762-12",
            "amount": 1054.5,
        }
    ]

}

Now I want to generate a report to group and count the number of itemCode in my collection in MongoDBCompass, so I did the following pipeline aggregation:

1- $unwind { path: "$response.results" }

2- $group { "_id": "$response.results.itemCode", quantity: { $sum: 1 }}

and I got the below result (this is a one item result only):

Sample result1

Now I just wanted to be sure that this is the correct result, so I searched for a specific item, so I did the following pipeline:

1- $unwind { path: "$response.results" }

2- $match {"response.results.itemCode": "39-762-12"}

3- $group { "_id": "$response.results.itemCode", quantity: { $sum: 1 }}

and the result got changed like this:

second result

any hint why this is happening? please help

1
  • Just found the issue, I have increased the limit from the settings for more than 100 thousand, I made it 9 million and it works fine :) Nov 17 at 14:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.