Hacker News new | ask | show | jobs
by Kiro 3776 days ago
I use MongoDB because I can instantly save down a JavaScript object and later retrieve it in the same state. I don't have to worry about anything else. No configuration, nothing. That's all I need but if there are better options I'm all ears.
4 comments

You're not "saving down a JavaScript object", as MongoDB does not speak JavaScript. What you're doing is passing an object to your database driver, which then converts it to JSON, and sends it to MongoDB.

JSON is an entirely separate language from JavaScript, and it can be used from just about any language. This "convert a native object into the query format" thing is also literally what almost every database driver in almost every language does.

This has precisely zero to do with either MongoDB or JavaScript.

Ok, so I'm saving it down as a JavaScript Object Notation which looks exactly the same as JavaScript. I think that's very convenient and don't see how it's the same as converting for example PHP to MySQL where I'm bound by a schema which looks nothing like my data structure in PHP.
> JavaScript Object Notation which looks exactly the same as JavaScript.

Whether it looks the same is irrelevant. It doesn't even have the same syntax rules. For example, this is valid JavaScript:

    {
        one: "two",
        three: undefined
    }
... but would be completely invalid in JSON, in more than one way. No, they are not the same.

> don't see how it's the same as converting for example PHP to MySQL where I'm bound by a schema which looks nothing like my data structure in PHP

And in 99% of cases, this is a feature, because you can't represent most data as a flat list of nested objects. See also this article: http://www.sarahmei.com/blog/2013/11/11/why-you-should-never...

Aside from that, if you want a native nested representation of data in your database, so including relations, you use an ORM. For example, in PHP with MySQL, you might use Eloquent.

How data is represented in your application and how it's represented in the database, are two entirely different things. There's no advantage to be gained from trying to make them the same thing - that's the concern of the database abstraction that you choose to use.

It's not irrelevant for me. When I look at a record in my database it looks the same as when defining it in code. This is a big advantage for me. Using an ORM is way more complicated than just inserting/retrieving my JS object. As I said, I don't want to configure stuff. I just want to save the object and be able to retrieve it by some key in the object.
> No configuration, nothing.

You still have a server to run, auth to check, etc...

Here's a real database with no configuration, no nothing, actual real plug-and-play:

https://sqlite.org/index.html

It's nice with zero configuration. Especially the no password by default thing. Why bother with limiting your database with host access and passwords ;)
I use environment variables so the configuration is basically setting up the host/username/pw in the Heroku interface. But ok, almost no configuration then...
You can do that with almost any language and any storage. JSON.