1

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):

Further reference(s):

B--rian
  • 5,578
  • 10
  • 38
  • 89
  • 1
    I just learned about `var content = cat('foo.png.b64'); db.icons.insert({'picture':content})` if I did `base64 foo.png > foo.png.b64` upfront. – B--rian Mar 01 '19 at 22:43

0 Answers0