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?
- is related to
-
CSHARP-5416 GetType not equals comparison translates incorrectly to MQL
- Closed