Opening GridFS MongoDB by name using C # driver

Pymongo has the ability to open GridFS with a specific collection name. For instance. mygridfs = gridfs.GridFS(db, collection = mycolc).

I cannot find a similar option in the MongoDB C # driver (official version of the latest version of MongoDB).

As a result, if I want to share GridFS data between Python and C # modules, I can only use GridFS by default in the database (named "fs").

Any hints, can I somehow access GridFS with a name other than the default in the C # MongoDB driver?

+4
source share
1 answer

An example using a grid in C #:

var url = new MongoUrl("mongodb://localhost");
var Client = new MongoClient(url);
var Server = Client.GetServer();
var Database = Server.GetDatabase("test");
var collection = Database.GetCollection("test");

var set = new MongoGridFSSettings {UpdateMD5 = true, ChunkSize = 512*1024, VerifyMD5 = false};

// you can set the name here
set.Root = "mycol";
var grid = Database.GetGridFS(set);

// Upload
grid.Upload(@"C:\Users\Hamid\Desktop\sample.txt", "remote");

// Download
grid.Download(@"C:\Users\Hamid\Desktop\sample2.txt", "remote");    
+5
source

Source: https://habr.com/ru/post/1568199/


All Articles