I have a directory with loads of small images (say png
icons) which I want to store in my MongoDB without using GridFS, ideally using a bash script and the mongo shell alone. From what I read, that seems technical feasible, but I did not yet manage to get it working. The official documentation but the recipe seems incomplete.
According to Christoph Menge, GridFS is indeed not absolutely necessary for e.g. icons only.
Assume, I have a image file called foo.png
which I would like to persist into the database icons
, the GridFS solution would be this:
mongofiles -u "uploader" -p "notsogreat" --authenticationDatabase "admin" -d icons put foo.png
But how do I do that without GridFS within bash
?
base64 foo.png > mongo -u "uploader" -p "notsogreat" --authenticationDatabase "admin" [SOME_MAGIC]
StackOverflow pages I consulted (in no particular order):
- Store images in a MongoDB database
- Store images in MongoDB
- How can I add images in mongoDB?
- Read image file into a MongoDB document's binary field via mongo shell script
- How do I insert a binary file into mongodb using javascript?
- Redirecting the output to a text file in MongoDB
- How to add binary data with objectId to mongoDB?
- Read a file from a mongo shell
Further reference(s):