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

GridFSFileInfo.Id projection broken

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 3.1.0
    • Affects Version/s: 3.0.0
    • Component/s: GridFS
    • None
    • Fully Compatible
    • Dotnet Drivers
    • Not Needed

      Summary

      If we query a gridfs collection and just want to retrieve the Id we had this code prior to upgrading to V3 driver:

      var id = await db
        .GetCollection<GridFSFileInfo>()
        .Find(Builders<GridFSFileInfo>.Filter.Empty) // For simplicity
        .Project(x => x.Id)
        .SingleOrDefaultAsync(); 

      After upgrading to V3 driver you get this exception:

      System.InvalidOperationException: Serializer for MongoDB.Driver.GridFS.GridFSFileInfo does not have a member named Id. 

      As a workaround i have this code now but IdAsBsonValue is obsolete.

      var id = (await db.GetCollection<GridFSFileInfo>() .Find(Builders<GridFSFileInfo>.Filter.Empty) // For simplicity 
      .Project(x => x.IdAsBsonValue) 
      .SingleOrDefaultAsync())
      ?.AsObjectId;  

      Now I'm unsure if it is an intended change within V3 driver or should we create own POCO classes if we want to load minimal data from GridFS?

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            danik.raikhlin@outlook.com DanikRaikhlin N/A
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: