Azure-docs: $setDifference is not properly working

Created on 17 Apr 2020  Â·  11Comments  Â·  Source: MicrosoftDocs/azure-docs

Given:

db.myCollection

{ "_id" : ObjectId("5e993fa7324aaf1724689781"), "name" : "John" }
{ "_id" : ObjectId("5e993fb7324aaf1724689782"), "name" : "Daniel" }
{ "_id" : ObjectId("5e993fbd324aaf1724689783"), "name" : "Eric" }
{ "_id" : ObjectId("5e993fc6324aaf1724689784"), "name" : "David" }

When I run the aggregate pipeline:

db.myCollection.aggregate([
    {
        $group: {
            "_id": null,
            "accts": { "$push": "$$ROOT.name" }
        }
    },
    { $project: { _id: 0, accts: 1} },
    { $project: { accts: { $setDifference: [ ["David", "Clayton"], "$accts" ] } } },
    { $unwind: "$accts" }
  ])

It SHOULD return the set difference of names:

Expected: ["Clayton"]
CosmosDB Result:
Operation consumed 7.38 RUs

{ "accts" : "David" }
{ "accts" : "Clayton" }
{ "accts" : "John" }
{ "accts" : "Daniel" }
{ "accts" : "Eric" }
{ "accts" : "David" }

I have confirmed that the above aggregate pipeline works properly in MongoDB. This looks like a bug in Cosmos; please confirm.


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Pri2 awaiting-product-team-response cosmos-dsvc cosmosdb-mongsubsvc cxp product-issue triaged

Most helpful comment

@Cephei Fix has been checked in and will be released with the next production deployment (30 days).

All 11 comments

Just checked, $setIntersection seems to work properly - so I'm a bit more confident this is an actual bug.

@Cephei, thank you for reaching out. We are looking into this and would get back to you soon on this thread.

@Cephei, Thank you for taking the time to report this issue.
I was able to repro it and we are working internally with the product group on this.
I will provide more updates here as and when I have them.

@KalyanChanumolu-MSFT jasontho and lbosq are the SMEs, please add them to your thread if you don't already have them.

@Cephei Can you confirm the endpoint this test is being run against.

This is being investigated but please ensure you are using the 3.6 endpoint (.mongo.cosmos.azure.com) and not the Mongo 3.2 endpoint (. documents.azure.com).

Thanks!

Yep, 100% sure I'm using 3.6. Should be easy to quickly test in the Cosmos Data Explorer in Azure. That's what I was using. The other SET-based functions work just fine: at least what I tested (intersection, union).

@Cephei This is likely a bug but I need to redirect this out of MicrosoftDocs and present this to the product group. Can you please send me an email with your instance name and your subscription GUID to AzCommunity. I can leverage the details of the issue from this issue but need your instance and subscription information as part of the investigation. Thank you!

@Cephei One additional detail. You have shared what you are expecting to see but can you share what you are are actually seeing? Thank you!

You can see in the original post:
Expected: [{ "accts": "Clayton" }]

Actual CosmosDB Result:
{ "accts" : "David" }
{ "accts" : "Clayton" }
{ "accts" : "John" }
{ "accts" : "Daniel" }
{ "accts" : "Eric" }
{ "accts" : "David" }

... it's not really doing anything but concatenating the sets

@Cephei Thank you for the additional detail. This issue is being tracked internally and I will close this specific item but, I will update this when a final update is made available for your awareness. If there are further updates you would like to make please feel free to continue the dialog.

@Cephei Fix has been checked in and will be released with the next production deployment (30 days).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DeepPuddles picture DeepPuddles  Â·  3Comments

varma31 picture varma31  Â·  3Comments

bdcoder2 picture bdcoder2  Â·  3Comments

Ponant picture Ponant  Â·  3Comments

spottedmahn picture spottedmahn  Â·  3Comments