Here is my Mongo document after migrating from SQL Server to regular MongoDB collection.
{
"TicketId": 23,
"Attachments" : [
{
"_id" : 4221,
"Name" : "profile Pic",
"Size" : 218112,
"Description" : "User Profile Pic",
"Data" :{ "$binary" : "0M8R4KGxGuE.............",
"IsPrivate" : false,
"AttachmentType" = {
"ContentType" = "image/png",
"FileExtension" = ".png"
},
"CreatedByUserId" : 12,
"CreatedDateTimeUtc" : ISODate("2012-05-21T18:40:08.570Z"),
},
{ // Another attachment },
{ // Another attachment },
{ // Another attachment }]
}
But I have attachment which are over 16 MB size, since MongoDB document size is limited to 16 MB I cannot use this approach to save my attachments.
Looks like GridFS is a right approach to save files in MongoDB I found this answer on SO https://stackoverflow.com/a/4990536/942855 which explains how to save a new file to GridFS. But I need to be able to migrate data from SQL Server to MongoGridFS.
Also when you upload a file to GRIDFS, it seems like it generates few default fields, I was wondering how can I add additional fields to it to Map to other collections?
Or should I consider keep all info related attachment with other mapping collection and add array of gridFsInfo.Id to it for mapping?
I am using MongoDB 3.2 with MongoDB C# driver