-
Type: Bug
-
Resolution: Done
-
Priority: Minor - P4
-
Affects Version/s: 2.1
When projecting a boolean value derived from comparing a field to a constant the constant should be serialized using the field's serializer.
One example showing why this is necessary is:
public enum E { A, B } public class C { public int Id { get; set; } [BsonRepresentation(BsonType.String)] public E E { get; set; } } public static class Program { public static void Main(string[] args) { var client = new MongoClient("mongodb://localhost"); var database = client.GetDatabase("test"); var collection = database.GetCollection<C>("test"); var queryable = collection.AsQueryable().Select(x => x.E == E.A); Console.WriteLine(queryable.ToString()); } }
The output is:
aggregate([{ "$project" : { "__fld0" : { "$eq" : ["$E", 0] }, "_id" : 0 } }])
but should be:
aggregate([{ "$project" : { "__fld0" : { "$eq" : ["$E", "A"] }, "_id" : 0 } }])
(i.e. "$E" should be compared to "A", not 0)