How do I store blob data in MongoDB?

22,995

Solution 1

There is no problem to store large files in the database. Use mongofiles See

Article on mongodb.com

Solution 2

Absolutely not. And before some fool just responds "GridFS", please read the documentation in the link.

Now that you have actually read the docs, consider that your blob (binary) data is probably under the 16MB BSON limitation. In which case, the answer is just Base64 encode it and put it into a field of your document.

Very Simple.

Share:
22,995
NAVNEET MATHPAL
Author by

NAVNEET MATHPAL

Updated on July 17, 2022

Comments

  • NAVNEET MATHPAL
    NAVNEET MATHPAL almost 2 years

    I want to know if it's possible to insert blob data in mongodb. What is the procedure and is any other softwares required for this?

  • mnemosyn
    mnemosyn over 10 years
    base64? Why? I mean, yes, disk is cheap, but that's just willful intent.
  • Neil Lunn
    Neil Lunn over 10 years
    @mnemosyn Yes it is valid to just post in the binary data, or anything else supported in BSON. I guess I'm kind of on autopilot for the usual follow up of "wanting to embed image in web page" and images seems to be mostly what people are wanting to store
  • niceman
    niceman almost 7 years
    maybe something like "GridFS is mainly for distributing large files into chunks" would be good
  • Aziuth
    Aziuth about 4 years
    I find this answer lacking, in the regard that the 16MB limitation is only an assumption. I am right now searching for this very topic, which landed me here, and I do in fact have data above that limit, potentially even several gigabytes in size (results of scientifical computations). If you have experience wth MongoDB, I'd implore you to make this case distinction. (Well, not sure if it is that useful to update a four year old answer, but again, I found it very quickly searching for mongodb and blobs, so has some significance.)
  • mckenzm
    mckenzm over 2 years
    Base64 will of course bloat the object further and require CPU to store and retrieve,