gpt4 book ai didi

c# - 使用 C# 驱动程序按名称打开 MongoDB GridFS

转载 作者:可可西里 更新时间:2023-11-01 09:12:22 25 4
gpt4 key购买 nike

在 pymongo 中,有一个选项可以打开具有特定集合名称的 GridFS。例如。 mygridfs = gridfs.GridFS(db, collection = mycolc)

我在 MongoDB C# 驱动程序(官方 MongoDB 最新驱动程序版本)中找不到类似的选项。

因此,如果我想在 Python 和 C# 模块之间共享 GridFS 数据,我只能使用数据库中的默认 GridFS(名为“fs”)。

关于我是否可以在 C# MongoDB 驱动程序中以某种方式访问​​具有非默认名称的 GridFS 的任何线索?

最佳答案

在 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");

关于c# - 使用 C# 驱动程序按名称打开 MongoDB GridFS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27553205/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com