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

Support projecting a single field with Find on servers prior to 4.4

    • Type: Icon: New Feature New Feature
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 2.21.0
    • Affects Version/s: None
    • Component/s: None
    • None
    • Not Needed
    • 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

      Projection on document ID alone creates invalid projection.

      C# Driver Version: 2.19.1, 2.19.2

      MongoDB Version: 4.0, 4.2
      MongoDB Topology: Using the Mongo driver for Azure; sharded cluster I think?

      How to Reproduce

      Attached is a small console application to demonstrate the error. I tested with both a string ID and an ObjectId ID, but both fail: strings are null, ObjectIDs are empty.

      The projection is pretty simple, in the test case, it's just:

      collection.Find(_ => true).Project(x => x.Id)

      (Finding all documents just for the small test I have.)

      However, the projection it generates in v2.19+ is:

      find({ }, { "_v" : "$_id", "_id" : 0 })

      In prior versions (we were using 2.14), this code worked, and the generated projection is what I'd have expected:

      find({ }, { "_id" : 1 })

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            shawn.weaver@americanautoshield.com Shawn Weaver
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: