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

GridFSFileInfo.Id projection broken

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: 3.0.0
    • Component/s: GridFS
    • None
    • Dotnet Drivers

      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:
            boris.dogadov@mongodb.com Boris Dogadov
            Reporter:
            danik.raikhlin@outlook.com DanikRaikhlin N/A
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: