[CSHARP-1865] Unsupported filter exception after upgrading from 2.3 to 2.4 driver Created: 12/Dec/16  Updated: 07/Feb/17  Resolved: 22/Dec/16

Status: Closed
Project: C# Driver
Component/s: Linq
Affects Version/s: 2.3
Fix Version/s: 2.4.1

Type: Bug Priority: Major - P3
Reporter: Paul Wen Assignee: Robert Stam
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows 10 x64, Visual Studio 2015, asp.net core C# mongodb driver


Issue Links:
Duplicate
duplicates CSHARP-1867 Non-nullable members cannot be compar... Closed
Related
is related to CSHARP-1867 Non-nullable members cannot be compar... Closed

 Description   

The following C# code was working with Mongodb C# driver 2.3 until we upgraded to 2.4 and are now receiving an exception: Unsupported filter: (Convert({document}{QueryId}) == 44).

var collection = _database.GetCollection<AgentAnswer>("answers");
var scount = collection.AsQueryable()
               .Where(p => p.QueryId == id)
               .Where(p => p.LastUpdated > utc)
               .GroupBy(a => a.AgentId)
               .Distinct().Count();

This is example data within the collection:

{ "_id" : ObjectId("58480a1c51d9399d679e5c18"), "AgentId" : "825c47da-4498-4b99-8ba7-08d3e7e9e8cb", "Answers" : [ { "Computer" : "bm-DEV", "accounttype" : "512", "caption" : "bm-DEV\\bm", "domain" : "bm-DEV", "sid" : "S-1-5-21-652548636-764486669-3140530632-500", "fullname" : "", "name" : "bm" }, { "Computer" : "bm-DEV", "accounttype" : "512", "caption" : "bm-DEV\\DefaultAccount", "domain" : "bm-DEV", "sid" : "S-1-5-21-652548636-764486669-3140530632-503", "fullname" : "", "name" : "DefaultAccount" }, { "Computer" : "bm-DEV", "accounttype" : "512", "caption" : "bm-DEV\\Guest", "domain" : "bm-DEV", "sid" : "S-1-5-21-652548636-764486669-3140530632-501", "fullname" : "", "name" : "Guest" } ], "QueryId" : 44, "LastUpdated" : ISODate("2016-12-12T20:43:17.328Z") }

The full exception stack trace is as follows:

   at MongoDB.Driver.Linq.Translators.PredicateTranslator.Translate(Expression node)
   at MongoDB.Driver.Linq.Translators.PredicateTranslator.Translate(Expression node, IBsonSerializerRegistry serializerRegistry)
   at MongoDB.Driver.Linq.Translators.QueryableTranslator.TranslateWhere(WhereExpression node)
   at MongoDB.Driver.Linq.Translators.QueryableTranslator.Translate(Expression node)
   at MongoDB.Driver.Linq.Translators.QueryableTranslator.TranslateWhere(WhereExpression node)
   at MongoDB.Driver.Linq.Translators.QueryableTranslator.Translate(Expression node)
   at MongoDB.Driver.Linq.Translators.QueryableTranslator.TranslateGroupBy(GroupByExpression node)
   at MongoDB.Driver.Linq.Translators.QueryableTranslator.Translate(Expression node)
   at MongoDB.Driver.Linq.Translators.QueryableTranslator.TranslateGroupBy(GroupByExpression node)
   at MongoDB.Driver.Linq.Translators.QueryableTranslator.Translate(Expression node)
   at MongoDB.Driver.Linq.Translators.QueryableTranslator.TranslateGroupBy(GroupByExpression node)
   at MongoDB.Driver.Linq.Translators.QueryableTranslator.Translate(Expression node)
   at MongoDB.Driver.Linq.Translators.QueryableTranslator.TranslatePipeline(PipelineExpression node)
   at MongoDB.Driver.Linq.Translators.QueryableTranslator.Translate(Expression node)
   at MongoDB.Driver.Linq.Translators.QueryableTranslator.Translate(Expression node, IBsonSerializerRegistry serializerRegistry, ExpressionTranslationOptions translationOptions)
   at MongoDB.Driver.Linq.MongoQueryProviderImpl`1.Execute(Expression expression)
   at MongoDB.Driver.Linq.MongoQueryProviderImpl`1.Execute[TResult](Expression expression)
   at WebServer.Services.MongoStore.<GetCountByQueryId>d__10.MoveNext() in C:\Users\User\Source\Repos\WebServer\Services\MongoStore.cs:line 143

Again this was working just fine in the 2.3 driver and only started causing an exception after upgrading to 2.4.



 Comments   
Comment by Paul Wen [ 22/Dec/16 ]

No problem; we only make sure to compare with actual values and not null. Thank you so much for the help! Is there any ETA on 2.4.1 or a beta package for testing?

Comment by Robert Stam [ 22/Dec/16 ]

Fixed by the work on CSHARP-1867.

Comment by Robert Stam [ 22/Dec/16 ]

This looks like it's the same issue as CSHARP-1867.

You are comparing a non-nullable member (x.QueryId) to a nullable value (id).

Should work now.

Keep in mind though that if the value of id is null you probably won't match any documents in the database (presumably there are no QueryId with a value of null because in your POCO QueryId is an int, not a nullable int).

Comment by Paul Wen [ 19/Dec/16 ]

You should be able to reproduce with a class, such as below, and store these objects in a collection. Then when you try to read them back with the query, also below, then it will cause the exception that I originally posted. This is within an ASP.NET Core 1.1.0 application. The code below works fine with Mongo.Driver 2.3.0 but causes the exception with 2.4.0. I can provide a full solution if this does not reproduce for some reason. thank you much

    public class SimpleClass
    {
        [BsonId]
        [BsonIgnoreIfDefaultAttribute]
        public ObjectId Id { get; set; }
        public string SystemId { get; set; }
        public string TestString { get; set; }
        public int QueryId { get; set; }
        public DateTime LastUpdated { get; set; }
    }
 
        public async Task<int> SimpleFunction(int? id, DateTime newerThan)
        {
            try
            {
                var collection = _database.GetCollection<SimpleClass>("test1x");
 
                var utc = newerThan.ToUniversalTime();
 
                var count = collection.AsQueryable()
                    .Where(p => p.QueryId == id)
                    .Where(p => p.LastUpdated > utc)
                    .GroupBy(a => a.SystemId)
                    .Distinct().Count();
 
                return count;

Comment by Paul Wen [ 18/Dec/16 ]

This is the datatype: public int QueryId

{ get; set; }

I will work in the mean time to see if I can reproduce this exception in a small sample project that I can share with you.

Comment by Robert Stam [ 13/Dec/16 ]

What is the data type of the QueryId property of the AgentAnswer class?

I don't think I can attempt to reproduce this without that information.

Comment by Paul Wen [ 12/Dec/16 ]

Just to note those extra line breaks in the collection data example are not actually in the collection there was an issue it seems in copy/paste into this ticket.

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