Cannot pass expression to FindSync when document and projection are different

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Summary

      Please provide a clear and concise description of the bug.
      The signature of the FindSync extension method restricts the document and projection so that they must be the same. This prevents passing in an expression for the filter when they're different.

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

      2.14.1

      How to Reproduce

      Steps to reproduce. If possible, please include a Short, Self Contained, Correct (Compilable), Example.
      The following code won't compile:

      using IAsyncCursor<TestProjection> cursor =
          coll.FindSync(
              new ExpressionFilterDefinition<TestDocument>(x => x.A == 1),
              new FindOptions<TestDocument, TestProjection>()
              {
                  Projection = Builders<TestDocument>.Projection.Include(x => x.B)
              });
      

      Additional Background

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

      This can probably be fixed by changing IMongoCollectionExtensions.cs:943 to read as follows:

      public static IAsyncCursor<TProjection> FindSync<TDocument, TProjection>(this IMongoCollection<TDocument> collection, Expression<Func<TDocument, bool>> filter, FindOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default(CancellationToken))
      

            Assignee:
            Unassigned
            Reporter:
            David Golub (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: