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

Generic Collection throws "{document} is not supported." on ReplaceOneAsync

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.2.4
    • Component/s: API, Operations
    • Environment:
      OS: Windows 10, MongoDB: 3.2.9 (Windows Server 2008 R2 with SSL)

      When trying to add a generic class to the collection, MongoDB CSharp Driver throws an System.AggregateException exception.

      System.AggregateException was unhandled by user code
        HResult=-2146233088
        Message=Mindestens ein Fehler ist aufgetreten.
        Source=mscorlib
        StackTrace:
             bei System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
             bei System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
             bei System.Threading.Tasks.Task`1.get_Result()
             bei Dealz.ProductListing.Data.MongoDb.Repositories.TypedIndexRepository.<>c__1`1.<AddIndexAsync>b__1_0(Task`1 result) in D:\Projekte\CSharp\Dealz\src\Dealz.ProductListing.Data.MongoDb\Repositories\TypedIndexRepository.cs:Zeile 41.
             bei System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
             bei System.Threading.Tasks.Task.Execute()
        InnerException: 
             HResult=-2146233079
             Message={document} is not supported.
             Source=MongoDB.Driver
             StackTrace:
                  bei MongoDB.Driver.Linq.Translators.PredicateTranslator.GetFieldExpression(Expression expression)
                  bei MongoDB.Driver.Linq.Translators.PredicateTranslator.TranslateTypeComparisonQuery(Expression variableExpression, ExpressionType operatorType, ConstantExpression constantExpression)
                  bei MongoDB.Driver.Linq.Translators.PredicateTranslator.TranslateComparison(BinaryExpression binaryExpression)
                  bei MongoDB.Driver.Linq.Translators.PredicateTranslator.Translate(Expression node)
                  bei MongoDB.Driver.Linq.Translators.PredicateTranslator.TranslateAndAlso(BinaryExpression node)
                  bei MongoDB.Driver.Linq.Translators.PredicateTranslator.Translate(Expression node)
                  bei MongoDB.Driver.Linq.Translators.PredicateTranslator.Translate(Expression node, IBsonSerializerRegistry serializerRegistry)
                  bei MongoDB.Driver.Linq.Translators.PredicateTranslator.Translate[TDocument](Expression`1 predicate, IBsonSerializer`1 parameterSerializer, IBsonSerializerRegistry serializerRegistry)
                  bei MongoDB.Driver.ExpressionFilterDefinition`1.Render(IBsonSerializer`1 documentSerializer, IBsonSerializerRegistry serializerRegistry)
                  bei MongoDB.Driver.MongoCollectionImpl`1.ConvertWriteModelToWriteRequest(WriteModel`1 model, Int32 index)
                  bei System.Linq.Enumerable.<SelectIterator>d__5`2.MoveNext()
                  bei MongoDB.Driver.Core.Operations.BulkMixedWriteOperation.BatchHelper.<FindOrderedRuns>d__8.MoveNext()
                  bei MongoDB.Driver.Core.Misc.ReadAheadEnumerable`1.ReadAheadEnumerator.MoveNext()
                  bei MongoDB.Driver.Core.Operations.BulkMixedWriteOperation.BatchHelper.<GetBatches>d__6.MoveNext()
                  bei MongoDB.Driver.Core.Operations.BulkMixedWriteOperation.<ExecuteAsync>d__39.MoveNext()
               --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde ---
                  bei System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
                  bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
                  bei MongoDB.Driver.OperationExecutor.<ExecuteWriteOperationAsync>d__3`1.MoveNext()
               --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde ---
                  bei System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
                  bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
                  bei MongoDB.Driver.MongoCollectionImpl`1.<ExecuteWriteOperationAsync>d__61`1.MoveNext()
               --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde ---
                  bei System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
                  bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
                  bei MongoDB.Driver.MongoCollectionImpl`1.<BulkWriteAsync>d__22.MoveNext()
               --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde ---
                  bei System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
                  bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
                  bei MongoDB.Driver.MongoCollectionBase`1.<ReplaceOneAsync>d__39.MoveNext()
             InnerException: 
      

      I am using the following Model for the collection

      IndexedItem.cs
         public class IndexedItem
          {
              protected IndexedItem() { }
      
              public IndexedItem(string key, string value)
              {
                  Key = key;
                  Value = value;
              }
      
              public IndexedItem(string key, string value, string displayText) : this(key, value)
              {
                  DisplayText = displayText;
              }
      
              public string Key { get; set; }
              public string Value { get; set; }
              public string DisplayText { get; set; }
          }
      
          public class IndexedItem<T> : IndexedItem
          {
              public IndexedItem() : base()
              {
                  Type = typeof(T).FullName;
              }
      
              public IndexedItem(string key, string value) : this()
              {
                  Key = key;
                  Value = value;
              }
      
              public IndexedItem(string key, string value, string displayText) : this(key, value)
              {
                  DisplayText = displayText;
              }
      
              public string Type { get; }
          }
      
      TypedIndexedItemRepository.cs
             public async Task<QueryResult> AddIndexAsync<T>(IndexedItem<T> item, CancellationToken cancellationToken = default(CancellationToken))
              {
                  var indexCollection = productsDatabase.GetCollection<IndexedItem<T>>(IndexCollection);
      
                  var result = await indexCollection.ReplaceOneAsync(
                      i => i.GetType() == typeof(IndexedItem<T>) && i.Key == item.Key,
                      item,
                      new UpdateOptions
                      {
                          IsUpsert = true
                      },
                      cancellationToken: cancellationToken
                  );
      
                  if (result.IsAcknowledged && result.ModifiedCount > 0)
                      return QueryResult.Success;
      
                  return QueryResult.Failed();
              }
      

      The idea is to have *one* collection, to hold indexed item for multiple types, i.e. IndexedItem<User> to index the user (i.e. for AutoComplete functionality).

      Expected result:

      {
        "_t": "Dealz.ProductListings.Contracts.Tag, Dealz.ProductListings",
        "key" : "tagkey", 
        "value": "tagname",
        "displayText": "Some Name"
      }
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            TsengSR Tseng [X]
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: