[英]mongodb gridfs in C# new api
i am new with MongoDB, and i can't find GridFS. 我是MongoDB的新手,但是找不到GridFS。 Where can i get GridFS to store files now ? 我现在可以在哪里获取GridFS来存储文件?
I can get it this way: 我可以这样得到:
mongoClient = new MongoClient(Settings.Default.MongoDB);
var server = mongoClient.GetServer();
MongoDatabase = server.GetDatabase(Settings.Default.DatabaseName);
MongoDatabase.GridFS...
but GetServer() method is obsolete. 但是GetServer()方法已过时。
if I get database as here: 如果我在这里得到数据库:
MongoDatabase2 = mongoClient.GetDatabase(Settings.Default.DatabaseName);
MongoDatabase2.GridFS... not working
Then i receive IMongoDatabase instead MongoDatabase, and i didnt have GridFS. 然后我收到IMongoDatabase而不是MongoDatabase,而我没有GridFS。
Heureka!! Heureka! Got it! 得到它了! Give me the Nobel prize! 给我诺贝尔奖! :) :)
var grid = new MongoGridFS(new MongoServer(new MongoServerSettings {Server = new MongoServerAddress(host, port)}), databaseName, new MongoGridFSSettings());
grid.Upload(file.InputStream, file.FileName, new MongoGridFSCreateOptions
{
Id = imageId,
ContentType = file.ContentType
});
I have the same problem. 我也有同样的问题。 I did find something I thought would solve my problem, the class MongoGridFS. 我确实找到了我认为可以解决我的问题的类MongoGridFS。 My problem now is that it takes a MongoServer, as it's first arg and times out when I give it a new instance or complains about a connectionstring not found. 我现在的问题是,它需要一个MongoServer,因为它是第一个arg,并且在我给它一个新实例或抱怨找不到连接字符串时超时。
var grid = new MongoGridFS(new MongoServer(new MongoServerSettings { Server = new MongoServerAddress(Settings.Default.WizdooMongoConnectionString) }), Settings.Default.WizdooMongoDatabaseName, new MongoGridFSSettings());
grid.Upload(file.InputStream, file.FileName, new MongoGridFSCreateOptions
{
Id = imageId,
ContentType = file.ContentType
});
//Yealds: The settings property 'ConnectionString' was not found.
I suppose I need to give it a connectionstring, but I've been able to do CRUD fine in MongoDB without it. 我想我需要给它一个连接字符串,但是我可以在没有它的情况下在MongoDB中完成CRUD。 So weird for this service to require it all of a sudden. 对于这项服务突然要求它很奇怪。 Maybe you can make it work for you though. 也许您可以使它适合您。 I'm going to look in to it more when I have time... should work with correct config. 如果有时间,我将进一步研究...应该使用正确的配置。 If you get it to work pls give me a hint! 如果您能正常工作,请给我提示! Good luck! 祝好运! :) :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.