fancy
fancy

Reputation: 51463

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.

Upvotes: 3

Views: 994

Answers (2)

Marshall
Marshall

Reputation: 4766

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.

Upvotes: 7

j_mcnally
j_mcnally

Reputation: 6968

It depends mongo will be easier if u want to alter the data. It is basically a storage engine for json lol. Depends on your use case. If you think this will grow, you might as well use mongo. If your storage needs will never change use a json file.

Upvotes: 0

Related Questions