The following query is executed:
return Database .GetCollection<MyEntity>() .AsQueryable() .Where(x => x.StartDate <= instance && x.EndDate >= instance) .GroupBy(x => x.Key.Guid) .Select(x => x.First().Id) .ToList();
But, adding the condition $ in (see below), the following exception is generated:
An unhandled exception was thrown by the application. System.NotSupportedException: $ project or $ group does not support First ({document} {_ ID})
return Database .GetCollection<MyEntity>() .AsQueryable() .Where(x => guidKeys.Contains(x.Key.Guid)) // $in condition .Where(x => x.StartDate <= instance && x.EndDate >= instance) .GroupBy(x => x.Key.Guid) .Select(x => x.First().Id) .ToList();
I understand that the LINQ driver is not yet supported by the driver, but I do not understand how introducing this addition step (using $ in) can lead to incompatibility for the grouping step.
Can anyone explain why this is happening?
I am using MongoDB 3.2 with .NET Driver 2.2.2.
EDIT:
MyEntity looks something like this:
[BsonIgnoreExtraElements] public class MyEntity: BaseMongoDocument { [BsonId] [BsonRepresentation(BsonType.Binary)] public Guid Id { get; set; } [BsonRequired] [BsonElement("startDate")] public DateTime StartDate { get; set; } [BsonRequired] [BsonElement("endDate")] public DateTime EndDate { get; set; } [BsonRequired] [BsonElement("key")] public SquidDocument Key { get; set; } [BsonConstructor] private MyEntity() { } } public class SquidDocument { [BsonRequired] [BsonElement("guid")] public Guid Guid { get; private set; } [BsonRequired] [BsonElement("squid")] public string Squid { get; private set; } [BsonConstructor] private SquidDocument(Guid guid, string squid) { Guid = realSquid.Guid; Squid = realSquid.Value; } }
mongodb mongodb-query mongodb-.net-driver
davenewza
source share