C# 使用GridFS插入大型对象

C# 使用GridFS插入大型对象,c#,mongodb,gridfs,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(connection

由于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怎么样?