Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-4737

Linq3Implementation: MongoDB.Driver.Linq.ExpressionNotSupportedException

    • Type: Icon: Bug Bug
    • Resolution: Won't Fix
    • Priority: Icon: Blocker - P1 Blocker - P1
    • None
    • Affects Version/s: 2.20.0
    • Component/s: Builders
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      Summary

      When i use update multiple fields, and the fields are multiple arrays, I get ExpressionNotSupportedException

      MongoDB.Driver.Linq.ExpressionNotSupportedException: Expression not supported: b.Contributors.FirstMatchingElement().TransactionDetails.FirstOrDefault(t => (t.TransactionId == "b2231207-ad5c-4236-8517-5fdc5e7c5139")).
        at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToFilterTranslators.ToFilterFieldTranslators.MethodCallExpressionToFilterFieldTranslator.Translate (MongoDB.Driver.Linq.Linq3Implementation.Translators.TranslationContext context, System.Linq.Expressions.MethodCallExpression expression) [0x0011a] in <3907a4edc609468b9bf7e7be07687c1a>:0 
        at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToFilterTranslators.ToFilterFieldTranslators.ExpressionToFilterFieldTranslator.Translate (MongoDB.Driver.Linq.Linq3Implementation.Translators.TranslationContext context, System.Linq.Expressions.Expression expression) [0x00046] in <3907a4edc609468b9bf7e7be07687c1a>:0 
        at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToFilterTranslators.ToFilterFieldTranslators.MemberExpressionToFilterFieldTranslator.Translate (MongoDB.Driver.Linq.Linq3Implementation.Translators.TranslationContext context, System.Linq.Expressions.MemberExpression memberExpression) [0x0000c] in <3907a4edc609468b9bf7e7be07687c1a>:0 
        at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToFilterTranslators.ToFilterFieldTranslators.ExpressionToFilterFieldTranslator.Translate (MongoDB.Driver.Linq.Linq3Implementation.Translators.TranslationContext context, System.Linq.Expressions.Expression expression) [0x00039] in <3907a4edc609468b9bf7e7be07687c1a>:0 
        at MongoDB.Driver.Linq.Linq3Implementation.LinqProviderAdapterV3.TranslateExpressionToField[TDocument,TField] (System.Linq.Expressions.Expression`1[TDelegate] expression, MongoDB.Bson.Serialization.IBsonSerializer`1[TValue] documentSerializer, MongoDB.Bson.Serialization.IBsonSerializerRegistry serializerRegistry, System.Boolean allowScalarValueForArrayField) [0x00037] in <3907a4edc609468b9bf7e7be07687c1a>:0 
        at MongoDB.Driver.ExpressionFieldDefinition`2[TDocument,TField].Render (MongoDB.Bson.Serialization.IBsonSerializer`1[TValue] documentSerializer, MongoDB.Bson.Serialization.IBsonSerializerRegistry serializerRegistry, MongoDB.Driver.Linq.LinqProvider linqProvider, System.Boolean allowScalarValueForArrayField) [0x00006] in <3907a4edc609468b9bf7e7be07687c1a>:0 
        at MongoDB.Driver.ExpressionFieldDefinition`2[TDocument,TField].Render (MongoDB.Bson.Serialization.IBsonSerializer`1[TValue] documentSerializer, MongoDB.Bson.Serialization.IBsonSerializerRegistry serializerRegistry, MongoDB.Driver.Linq.LinqProvider linqProvider) [0x00000] in <3907a4edc609468b9bf7e7be07687c1a>:0 
        at MongoDB.Driver.OperatorUpdateDefinition`2[TDocument,TField].Render (MongoDB.Bson.Serialization.IBsonSerializer`1[TValue] documentSerializer, MongoDB.Bson.Serialization.IBsonSerializerRegistry serializerRegistry, MongoDB.Driver.Linq.LinqProvider linqProvider) [0x00000] in <3907a4edc609468b9bf7e7be07687c1a>:0 
        at MongoDB.Driver.CombinedUpdateDefinition`1[TDocument].Render (MongoDB.Bson.Serialization.IBsonSerializer`1[TValue] documentSerializer, MongoDB.Bson.Serialization.IBsonSerializerRegistry serializerRegistry, MongoDB.Driver.Linq.LinqProvider linqProvider) [0x0001b] in <3907a4edc609468b9bf7e7be07687c1a>:0 
        at MongoDB.Driver.MongoCollectionImpl`1[TDocument].ConvertWriteModelToWriteRequest (MongoDB.Driver.WriteModel`1[TDocument] model, System.Int32 index) [0x0028b] in <3907a4edc609468b9bf7e7be07687c1a>:0 
        at System.Linq.Enumerable+<SelectIterator>d154`2[TSource,TResult].MoveNext () [0x0005a] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/System.Linq/src/System/Linq/Select.cs:83 
        at System.Collections.Generic.List`1[T].AddEnumerable (System.Collections.Generic.IEnumerable`1[T] enumerable) [0x00059] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/Common/src/CoreLib/System/Collections/Generic/List.cs:1108 
        at System.Collections.Generic.List`1[T]..ctor (System.Collections.Generic.IEnumerable`1[T] collection) [0x00062] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/Common/src/CoreLib/System/Collections/Generic/List.cs:87 
        at System.Linq.Enumerable.ToList[TSource] (System.Collections.Generic.IEnumerable`1[T] source) [0x0000e] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/System.Linq/src/System/Linq/ToCollection.cs:30 
        at MongoDB.Driver.Core.Operations.BulkMixedWriteOperation..ctor (MongoDB.Driver.CollectionNamespace collectionNamespace, System.Collections.Generic.IEnumerable`1[T] requests, MongoDB.Driver.Core.WireProtocol.Messages.Encoders.MessageEncoderSettings messageEncoderSettings) [0x0000d] in <01310fd52db547f38c442be4cf246118>:0 
        at MongoDB.Driver.MongoCollectionImpl`1[TDocument].CreateBulkWriteOperation (MongoDB.Driver.IClientSessionHandle session, System.Collections.Generic.IEnumerable`1[T] requests, MongoDB.Driver.BulkWriteOptions options) [0x00033] in <3907a4edc609468b9bf7e7be07687c1a>:0 
        at MongoDB.Driver.MongoCollectionImpl`1[TDocument].BulkWriteAsync (MongoDB.Driver.IClientSessionHandle session, System.Collections.Generic.IEnumerable`1[T] requests, MongoDB.Driver.BulkWriteOptions options, System.Threading.CancellationToken cancellationToken) [0x0009e] in <3907a4edc609468b9bf7e7be07687c1a>:0 
        at MongoDB.Driver.MongoCollectionImpl`1[TDocument].UsingImplicitSessionAsync[TResult] (System.Func`2[T,TResult] funcAsync, System.Threading.CancellationToken cancellationToken) [0x000fe] in <3907a4edc609468b9bf7e7be07687c1a>:0 
        at MongoDB.Driver.MongoCollectionBase`1[TDocument].UpdateOneAsync (MongoDB.Driver.FilterDefinition`1[TDocument] filter, MongoDB.Driver.UpdateDefinition`1[TDocument] update, MongoDB.Driver.UpdateOptions options, System.Func`3[T1,T2,TResult] bulkWriteAsync) [0x00148] in <3907a4edc609468b9bf7e7be07687c1a>:0 
        at Infrastructure.Database.CosmoMongoDb.DeactivateReceiverFundingAsync (System.String fundingId, System.String allocationId) [0x00730] in C:\Dev\Repos\SensoDrive.Mobile\Infrastructure\Database\CosmoMongoDb.cs:1845 

       

      Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).

      How to Reproduce

      Steps to reproduce. If possible, please include a Short, Self Contained, Correct (Compilable), Example.

                     var builder = Builders<Funding>.Filter;
                      var filter = builder.Eq(f => f.FundingId, fundingId) &
                                   builder.ElemMatch(e => e.Receivers, r => r != null && r.AllocationId == receiver.AllocationId);
                      var update = Builders<Funding>.Update.Set(b => b.Receivers.FirstMatchingElement().IsActive, false)
                          .Set(b => b.Receivers.FirstMatchingElement().IsDefault, false)
                          .Set(b => b.Receivers.FirstMatchingElement().ExpiryDateTime, DateTime.UtcNow)
                          .Set(b => b.Receivers.FirstMatchingElement().AllocatedAmount, receiver.UsedAmount)
                          .Set(b => b.Contributors.FirstMatchingElement().TransactionDetails.FirstOrDefault(t => t.TransactionId == receiver.FromTransactionId).AllocatedAmount, transaction.AllocatedAmount - credit);

                      var result = await FundingsCollection.UpdateOneAsync(filter, update);

       

      Additional Background

      Please provide any additional background information that may be helpful in diagnosing the bug.

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            sasan.pasha@gmail.com Sasan Pasha
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: