使用GridFS插入大对象

时间:2014-05-11 06:47:27

标签: c# mongodb gridfs

由于MongoDB本身目前每个文档限制为16MB,我正在尝试使用GridFS来克服障碍。

目前,我的代码看起来像是:

const string INPUT_FILE = @"C:\Users\...\CP001814.gbk";

// Set up connection to database
string connectionString = "mongodb://localhost";
MongoClient client = new MongoClient(connectionString);
MongoServer server = client.GetServer();
MongoDatabase db = server.GetDatabase("genomedb");
MongoGridFS grid = new MongoGridFS(server, "genomedb", new MongoGridFSSettings());

// do something with the input file which returns an ISequence 'sequence' object

MongoGridFSStream stream = grid.Create("CP003814.gbk");
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(stream, sequence);
MongoGridFSFileInfo info = db.GridFS.Upload(stream, "CP003814.gbk_sequence");
stream.Close();

我在这里做错了什么?目前,当我运行它时,它会创建fs.files文件元数据,长度= 0,并且fs.chunks上没有任何内容。

0 个答案:

没有答案