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

Cannot pass expression to FindSync when document and projection are different

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major - P3 Major - P3
    • None
    • None
    • None
    • None

    Description

      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))
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            david.golub@mongodb.com David Golub
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: