Store data with up to 800 lines of code as strings or files?

Hi!

I´m currently developing a scanning software, where the user can upload his code (with up too about 500-800 lines of code - sometimes only 20 lines of code) for a scan.
I´m storing the content in my db and am wondering, if it´s mroe efficient to store potentially “huge” files as a string or file in my database.
I couldn´t really find a specific case for my question, because it´s really flexible and so on.

So yeah, there can and will be those files with hundreds of lines of code. What would you say is the more efficient way to store those?

Cheers!

Welcome to the MongoDB Community @Daniel_Mielke!

You can store up to 16MB in a single MongoDB document, so hundreds of lines of code isn’t particularly huge. Taking 100 characters as a (probably large) average line length, 800 lines of code would still be less than 100KB of text.

For comparison, the Complete Works of William Shakespeare is 5.5MB in plain text format.

The most efficient approach depends on your use case.

How do you plan to access the code contents? If you will be scanning, searching, or indexing in some way and need to retain the code contents, then it would make sense to save the metadata (and perhaps the contents) in MongoDB. I assume your use case may have several steps of scanning and processing the code.

If your scanning software only needs the file contents transiently, it may be more efficient to save to temporary files on disk and remove after processing.

Regards,
Stennie

1 Like