把文件二进制数据存入mongodb

               //存入,photoData.Data为二进制文件数据
         var db = GetDB(); string filename = (new GridFSOP()).GridFsSave(photo.Data); MongoDB.Bson.BsonDocument doc = new MongoDB.Bson.BsonDocument(); doc["PhotoID"] = photo.PhotoID; doc["Name"] = photo.Name; doc["Description"] = photo.Description; doc["DateTime"] = photo.DateTime; doc["filename"] = filename; db["testTable"].Save(doc); public static MongoDatabase GetDB() { return MongoDatabase.Create(ConfigurationManager.ConnectionStrings["MongoDB_feni"].ConnectionString); } MongoDB_feni:mongodb://user:pwd@ip:27277/fenidb

你可能感兴趣的:(mongodb)