[CSHARP-1819] Gridfs Fails to filter on Metadata after upgrading to 2.3 Created: 02/Nov/16  Updated: 22/Dec/16  Resolved: 22/Dec/16

Status: Closed
Project: C# Driver
Component/s: GridFS
Affects Version/s: 2.3
Fix Version/s: None

Type: Bug Priority: Blocker - P1
Reporter: Stefan Weber Assignee: Robert Stam
Resolution: Done Votes: 0
Labels: c#, driver, gridfs
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Today i upgraded my nuget packages to version 2.3. Iam using a FilterDefinition on GridfsFileInfo like this:

var filter = Builders<GridFSFileInfo>.Filter.Eq(x => x.Metadata["ContainerId"],containerId);
 
var results = await this.Storage.Find(filter).ToListAsync();

Before this upgrade this worked, now iam getting an error:

System.MethodAccessException: Attempt by method 'MongoDB.Driver.GridFS.GridFSBucket.Find(MongoDB.Driver.FilterDefinition`1<MongoDB.Driver.GridFS.GridFSFileInfo>, MongoDB.Driver.GridFS.GridFSFindOptions, System.Threading.CancellationToken)' to access method 'MongoDB.Driver.BatchTransformingAsyncCursor`2<System.__Canon,System.__Canon>..ctor(MongoDB.Driver.IAsyncCursor`1<System.__Canon>, System.Func`2<System.Collections.Generic.IEnumerable`1<System.__Canon>,System.Collections.Generic.IEnumerable`1<System.__Canon>>)' failed.



 Comments   
Comment by Robert Stam [ 02/Nov/16 ]

I am unable to reproduce this. My test code is:

public static class Program
{
    public static void Main(string[] args)
    {
        var client = new MongoClient("mongodb://localhost");
        client.DropDatabase("test");
 
        var database = client.GetDatabase("test");
        var bucket = new GridFSBucket(database);
 
        var content = "Hello World";
        var source = Encoding.UTF8.GetBytes(content);
        var metadata = new BsonDocument
        {
            { "ContainerId", 123 }
        };
        var options = new GridFSUploadOptions { Metadata = metadata };
        bucket.UploadFromBytes("HelloWorld", source, options);
 
        var fileInfo = TestAsync(bucket).GetAwaiter().GetResult();
    }
 
    private static async Task<GridFSFileInfo> TestAsync(IGridFSBucket bucket)
    {
        var filter = Builders<GridFSFileInfo>.Filter.Eq(x => x.Metadata["ContainerId"], 123);
        var cursor = await bucket.FindAsync(filter);
        var fileInfos = await cursor.ToListAsync();
        return fileInfos.FirstOrDefault();
    }
}

Generated at Wed Feb 07 21:40:45 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.