Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing simple data on the server, db or json?

I have an app and it needs to store a few simple objects that change, and it needs to be able to persist them. Should I save the data to a db like mongo and read it in on startup or should I just save to a json file?

Thanks for any tips.

like image 514
fancy Avatar asked Mar 07 '26 01:03

fancy


1 Answers

Either way can work. 'It depends' which is best in your situation.

Things to consider:

  • Flat files are not (or not easily) queriable.
  • You will have to manage flat files (e.g. folders, file names, etc)
  • Is it possible that there will be a collision? Are you going to read & write often?
  • If you are only persisting a few objects, is a database like mongo overkill?
  • Is something like redis a better solution?

I'm currently working on a project that involves several data stores. MySQL, flat-files, mongo, et cetera.

The flat files work really well for storing data that will be pulled up later. It's suitable for data that isn't read or written often.

Mongo has modules like Mongoose that take away a lot of complexities. But the documentation for both Mongoose and Mongo can be a bit dry and confusing.

Think about how the data will be used, how it will evolve, and if you need to query it. If it just needs to be pulled up at the app's startup, then a flat file can work. If it is going to grow into larger objects then flat files can still be the solution. But if there's a chance for additional objects in the future, then flat-files will become harder to manage, and it will be a pain to add them into a working system.

And overall, if you want any type of querying (other than manually opening files and inspecting them) then go with Mongoose or a similar database.

like image 110
Marshall Avatar answered Mar 09 '26 13:03

Marshall



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!