When it comes to choosing a database,  What is the best for a Java project?

2.NoSQL- MongoDB

  • 6
    It depends. We'd need specifics to say. One is not by definition better than the other.
  • 4
    Do you need relationships or not?
  • 1
    @C0D4 i dont need relationship actually
  • 3
    We tried MongoDB and my recommendation is, if you do not know what your needs are for a database, go with an sql.

    Mongodb and other nosql databases are very good at some things but can be utterly impossible for other.

    And if you later find that you need the nosql, use both.

    At least until you know the nosql db good enough to know its the right choice.

    A relational is more flexible but it might not scale as good as a nosql.

    The real exception is social network problem, if you have that kind of problem use an sql + a graph db.
  • 6
    You could always use PostgreSQL. You have relations, but if you ever need to store json, you can do that
  • 0
    @Voxera very good explanation thank you.
  • 2
    @DawidCyron MySQL can store and use json aswell 😅
  • 2
    @DawidCyron The differences is how you can manipulate it.

    Mongodb can make changes directly into a stored object like adding an item to a list in the object without touching the rest.

    You could fir example add one item to a list in all objects witch has less than 4 in price and where the new item does not already exist.

    I do not know if postgres can do such manipulations, and what performance you get.

    BUT thats the scaling problem :), postgres CAN solve the problem for you and if you find you need the speed later you can always switch then.

    But MongoDb cannot really do relations, especially not with transactions.

    There are not join solution.

    So if a child need to be part if multiple parents in sql you just link to it with joins.

    In mongodb you have to store lists of ids and make multiple queries, which might get out of sync so your result is not consistent.

    You might find ways to solve this but it gets very complex fast.

    Almost any such situation would be better served by going multiple db.

    Sql as base, mongodb for object storage that do not need relations, a graph db to handle network relations, redis or similar for caching and messaging ...

    That way you can get the best from each type.

    But sql is still one of the most flexible, even if not the fastest.

    And with json storage you avoid the problem of multiple joins to get an objects data.
  • 1
    MariaDB is works fine!
  • 2
    Your language choice is irrelevant. What matters is what you are trying to accomplish.
  • 1
    I would also recommend YourSQL and TibetDB as alternatives :3
Add Comment