-
Type: Bug
-
Resolution: Duplicate
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
Summary
We have a helper library on top of the driver that wraps calls to UpdateManyAsync . I will include pseudocode in the following section. All of our consumers of this library are breaking if we try and update from version 2.18 to 2.19. As I am not expecting a compatibility breaking change in a minor version update I am posting an issue to see if this is an unexpected regression.
How to Reproduce
The following code shows what we are doing.
public async Task MarkAllAsDeleted(Expression<Func<MyEntry, bool>> filter) { // Define changes to apply to the database. var changes = new List<Tuple<Expression<Func<MyEntry, object>>, object>>(); changes.Add(new Tuple<Expression<Func<AddressGroupEntry, object>>, object (entry => entry.Deleted, true)); var mongoUpdateDefinition = ToMongoUpdateDefinition(changes); var collection = Context.Database.GetCollection<MyEntry>(CollectionName); await Collection.UpdateManyAsync(filter, mongoUpdateDefinition); // Result handling omitted } public static UpdateDefinition<TEntry> ToMongoUpdateDefinition<TEntry>(List<Tuple<Expression<Func<MyEntry, object>>, object>> changes) { var updates = new List<UpdateDefinition<TEntry>>(); foreach (var change in changes) { updates.Add(Builders<TEntry>.Update.Set(change.Item1 as dynamic, change.Item2 as dynamic)); } return Builders<TEntry>.Update.Combine(updates); }
After updating to 2.19, the above code generated a callstack like:
MongoDB.Driver.Linq.ExpressionNotSupportedException: Expression not supported: Convert(entry.Deleted, Object).\n at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToFilterTranslators.ToFilterFieldTranslators.ConvertExpressionToFilterFieldTranslator.Translate(TranslationContext context, UnaryExpression expression)\n at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToFilterTranslators.ToFilterFieldTranslators.ExpressionToFilterFieldTranslator.Translate(TranslationContext context, Expression expression)\n at MongoDB.Driver.Linq.Linq3Implementation.LinqProviderAdapterV3.TranslateExpressionToField[TDocument,TField](Expression\u00601 expression, IBsonSerializer\u00601 documentSerializer, IBsonSerializerRegistry serializerRegistry, Boolean allowScalarValueForArrayField)\n at MongoDB.Driver.ExpressionFieldDefinition\u00602.Render(IBsonSerializer\u00601 documentSerializer, IBsonSerializerRegistry serializerRegistry, LinqProvider linqProvider, Boolean allowScalarValueForArrayField)\n at MongoDB.Driver.ExpressionFieldDefinition\u00602.Render(IBsonSerializer\u00601 documentSerializer, IBsonSerializerRegistry serializerRegistry, LinqProvider linqProvider)\n at MongoDB.Driver.OperatorUpdateDefinition\u00602.Render(IBsonSerializer\u00601 documentSerializer, IBsonSerializerRegistry serializerRegistry, LinqProvider linqProvider)\n at MongoDB.Driver.CombinedUpdateDefinition\u00601.Render(IBsonSerializer\u00601 documentSerializer, IBsonSerializerRegistry serializerRegistry, LinqProvider linqProvider)\n at MongoDB.Driver.MongoCollectionImpl\u00601.ConvertWriteModelToWriteRequest(WriteModel\u00601 model, Int32 index)\n at System.Linq.Enumerable.SelectIterator[TSource,TResult](IEnumerable\u00601 source, Func\u00603 selector)\u002BMoveNext()\n at System.Collections.Generic.List\u00601..ctor(IEnumerable\u00601 collection)\n at System.Linq.Enumerable.ToList[TSource](IEnumerable\u00601 source)\n at MongoDB.Driver.Core.Operations.BulkMixedWriteOperation..ctor(CollectionNamespace collectionNamespace, IEnumerable\u00601 requests, MessageEncoderSettings messageEncoderSettings)\n at MongoDB.Driver.MongoCollectionImpl\u00601.CreateBulkWriteOperation(IClientSessionHandle session, IEnumerable\u00601 requests, BulkWriteOptions options)\n at MongoDB.Driver.MongoCollectionImpl\u00601.BulkWriteAsync(IClientSessionHandle session, IEnumerable\u00601 requests, BulkWriteOptions options, CancellationToken cancellationToken)\n at MongoDB.Driver.MongoCollectionImpl\u00601.UsingImplicitSessionAsync[TResult](Func\u00602 funcAsync, CancellationToken cancellationToken)\n at MongoDB.Driver.MongoCollectionBase\u00601.UpdateManyAsync(FilterDefinition\u00601 filter, UpdateDefinition\u00601 update, UpdateOptions options, Func\u00603 bulkWriteAsync)\n at NationalInstruments.NotificationService.DataStore.Providers.Mongo.MongoDataProvider\u00601.UpdateAsync(Expression\u00601 match, Changes\u00601 changes) in /app/NotificationService/NotificationService.DataStore/Providers/Mongo/MongoDataProvider.cs:line 290\n
Additional Background
- duplicates
-
CSHARP-4499 Support Convert calls to a base type in filter translators
- Closed
- is duplicated by
-
CSHARP-4501 Updating from version 2.18 to 2.19 of the C# MongoDB driver is breaking code to update documents in the database across a large codebase.
- Closed