Store files on disk or MongoDB

后端 未结 3 903
鱼传尺愫
鱼传尺愫 2021-01-02 06:03

I am creating a mongodb/nodejs blogging system (similar to wordpress).

I currently have the images being saved on the disk and a pointer being placed in mongo. I was

相关标签:
3条回答
  • 2021-01-02 06:43

    MongoDB is a good option to store your files (I'm talking about GridFS), specially for the use case you described above. When you store files into MongoDB (GridFS, not documents), you get all the replication and sharding capability for free, which is awesome.

    If you have to spawn a new server and you have the files already into MongoDB, all you have to do is to enable replication (thus scale horizontally). I'm sure this can save you a lot of headaches.

    Resources:

    Is GridFS fast and reliable enough for production?
    http://www.mongodb.org/display/DOCS/GridFS
    http://www.coffeepowered.net/2010/02/17/serving-files-out-of-gridfs/

    0 讨论(0)
  • 2021-01-02 06:54

    Storing the image as document in mongodb would be a bad idea, as the resources which could have been used to send a large amount of informational data would be used for sending files.

    Have a look at mongoDb file storage GridFS , that might solve your problem of storing images, and providing horizontal scalability as well.

    http://www.mongodb.org/display/DOCS/GridFS http://www.mongodb.org/display/DOCS/GridFS+Specification

    0 讨论(0)
  • 2021-01-02 06:57

    Aside from GridFS, you might be considering a cloud-based deployment. In that case, you might consider storing files in cloud-specific storage (Windows Azure has Blob Storage, for example). Sticking with Windows Azure for this example (since that's what I work with), you'd reference a file by its storage account URI. For example:

    https://mystorageacct.blob.core.windows.net/mycontainer/myvideo.wmv
    

    Since you'd be storing the MongoDB database itself in its own blob (and mounted as disk volume on your Linux or Windows VM), you could then choose to store your files in either the same storage account or a completely different storage account (with each storage account providing 100TB 200TB of storage).

    0 讨论(0)
提交回复
热议问题