[CSHARP-1101] invalid operator '$SetIntersection' - code 15999 Created: 12/Nov/14  Updated: 05/Apr/19  Resolved: 14/Nov/14

Status: Closed
Project: C# Driver
Component/s: API
Affects Version/s: 1.9.2
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: Mauro Micheli Assignee: Robert Stam
Resolution: Cannot Reproduce Votes: 0
Labels: question
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Official MongoCSharpDriver 1.9.2


Attachments: Text File Program.cs    

 Description   

I have a collection named ResourceTypeCategory with documents containing a list of value object named Properties. I need the intersection of the persisted array with an input array (see below)

db.ResourceTypeCategoryRoot.aggregate([ { "$project" : { "intersect" : { "$setIntersection" : ["$Properties.Acronym", ["ROY", "MAJ"]] } } } ]);

If i run this command on mongod shell it works fine but if i use the mongodb csharp driver method "Aggregate" in "Collection" class of official mongodbcsharpdriver i get this error:

"Command 'aggregate' failed: exception: invalid operator '$SetIntersection'"

This is my code:

            var pipeline = new BsonDocument[]
            {
                new BsonDocument
                {
                    { "$project", new BsonDocument
                            {
                                { "intersect", new BsonDocument
                                                        {
                                                            { "$setIntersection", new BsonArray
                                                                {   "$Properties.Acronym", 
                                                                    new BsonArray(propertyIds.ToArray())
                                                                }
                                                            }
                                                        }
                                    }
                                }
 
                       }
                }
            };
 
            var test = collection.Aggregate(pipeline);

Help!



 Comments   
Comment by Robert Stam [ 14/Nov/14 ]

You're welcome. I'm glad you got it working.

Comment by Mauro Micheli [ 14/Nov/14 ]

We reviewed all the solution and we found a mistake in app.config with server names.
The problem was exactly what you said since the beginning so ... thanks a lot!

Comment by Robert Stam [ 14/Nov/14 ]

I tried to reproduce this, but was unable to. Since I don't know what your documents look like or have any test data matching your documents, I used the example in the documentation for $setIntersection:

http://docs.mongodb.org/manual/reference/operator/aggregation/setIntersection/

I've attached the full test program (Progam.cs), but the relevant lines are:

    Console.WriteLine("Running test against server version: {0}", server.BuildInfo.Version);
    Console.WriteLine();
 
    var pipeline = new[]
    {
        new BsonDocument
        {
            { "$project", new BsonDocument
                {
                    { "A", 1 },
                    { "B", 1 },
                    { "commonToBoth", new BsonDocument("$setIntersection", new BsonArray { "$A", "$B" }) },
                    { "_id", 0 }
                }
            }
        }
    };
    var query = collection.Aggregate(new AggregateArgs { Pipeline = pipeline });
    foreach (var result in query)
    {
        Console.WriteLine(result.ToJson());
    }

And the output was:

Running test against server version: 2.6.5
 
{ "A" : ["red", "blue"], "B" : ["red", "blue"], "commonToBoth" : ["red", "blue"]
 }
{ "A" : ["red", "blue"], "B" : ["blue", "red", "blue"], "commonToBoth" : ["red",
 "blue"] }
{ "A" : ["red", "blue"], "B" : ["red", "blue", "green"], "commonToBoth" : ["red"
, "blue"] }
{ "A" : ["red", "blue"], "B" : ["green", "red"], "commonToBoth" : ["red"] }
{ "A" : ["red", "blue"], "B" : [], "commonToBoth" : [] }
{ "A" : ["red", "blue"], "B" : [["red"], ["blue"]], "commonToBoth" : [] }
{ "A" : ["red", "blue"], "B" : [["red", "blue"]], "commonToBoth" : [] }
{ "A" : [], "B" : [], "commonToBoth" : [] }
{ "A" : [], "B" : ["red"], "commonToBoth" : [] }

I am only able to reproduce your error message when I connect to a server older than version 2.6.

Comment by Mauro Micheli [ 12/Nov/14 ]

Yes , i'm sure.
If I try to execute on mongo shell it works fine, the problem is when i try from c#

Comment by Robert Stam [ 12/Nov/14 ]

The $setIntersection aggregation operator is new in version 2.6 of the server.

Are you sure that your C# program is connecting to a new enough version of the server?

Generated at Wed Feb 07 21:38:39 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.