node.js - Storing some small (under 1MB) files with MongoDB in NodeJS WITHOUT GridFS -


I run a website that runs on the backend of NodesJS + Mongodb Right now, I stored some icons (small image files) To implement a system, which should be in the database.

In my opinion, it does not make much sense to use the gridfase, because it seems to be large files or large numbers of files, because I need to save every file, so I would be fine under the BSN maximum file size, so I should be able to save them in regular documents.

I have 2 questions:

1) Is my argument correct? Is it okay to save the image files in a regular Mongo archive along with Gridfix? Am I not considering here that I should be?

2) If my thinking process is correct, how do I want to go about doing this? Can I do something like:

  // Assume that 'things' is a mongodibi collection created correctly using a node-monogode-driver fs.readFile ( PathToIconImage, function (err, image) {things .inert ({'image': image}, function (err, doc) {if (err) console.log ('you have an error!' + Err);}); }); I think that's probably a better way of doing this, because MongoDB uses BSON and even before saving it into the database, save a file in JSON. I am trying to I do not even know that this code will work (it has not been tried)  

Update - New Question

If three documents were saved in my archive Are: 1) a name, 2) a date, and 3) an image file (icon above), and I want to send this document to a client to display all three, will it be possible? If not, then I think I will need to use GridFS and save the file ID in my own place. Thoughts / suggestions?

Best, and thanks for any feedback,

If your images are really small then there is no problem in the size of the document, and if you do not pay attention to some extra processing, then it is probably okay to store it directly in your collection. To do this, if you want to convert the image to cipher 64, then store it using Mongo's BinData type. As I understand it, it then saves it as a BSON-Bit array, in fact the base does not store the 64 string, so the size will not grow larger than your original binary image.

This will appear in the Jason query as a base 64 string, which you can use to get the binary image back.

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -