Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

A fixed schema in the database means you only have one schema to deal with. But in schema-less DBMS you really have as many schemas as changes you've made. If you add a field to new records coming in, you now have 2 schemas. Every change you make is another schema.

Your ORM likely represents the last iteration of that schema and then you have code to handle all the past iterations.

So the point of having a schema in the database is avoiding that kind of hell.



  > in schema-less DBMS you really have as many schemas as 
  > changes you've made.
Unless you migrate data with each change, which is actually easier when you don't have a static schema. The choice to do "lazy migrations" is the unusual, not typical case, as it has all of the implications that you've mentioned. Bottom line: Data normalization doesn't suddenly go out the window just because it's MongoDB.


Usually if you have a static schema you also have SQL, which makes migrations a lot easier. If you're migrating everything with every change you might as well be using a static schema, there is hardly any downside, unless you have more rows than God.

My only personal opinion is that data is much more important than code. I want to guarantee that my data is in the right structure, with the right types, and right relationships. If I have that, everything else is easy.


  > Usually if you have a static schema you also have SQL,
  > which makes migrations a lot easier.
I'm not sure I follow. MongoDB doesn't have a static schema so there's less work to do when migrating data. No temp tables, no DDL, no disabling of triggers, etc. So my definition of "easy" in this case was "fewer things to do", not "requires less expertise."

  > I want to guarantee that my data is in the right
  > structure, with the right types, and right relationships.
We know that having the right types, structure, and relationships are valuable, but since there is no context here, we can't know whether they're more or less valuable than other factors. (Note we've already assumed that the data is easily modeled in a relational structure AND in a document structure... If we're wrong about that this whole conversation may be moot.)


> MongoDB doesn't have a static schema so there's less work to do when migrating data.

That depends on the operation. If I want add a column and provide a suitable default, that's a one-step process in a SQL database. Even better, I can do it from a GUI tool and generate SQL script ready to use in production. So my definition of easy is both fewer things to do and less expertise. Even taking a more complicated yet common example of taking a single field and turning it into a collection or table of values -- I think the SQL approach is still going to be less work. But I think the more complicated of a transformation you need, the less of a difference there is -- once you start writing a lot of code it doesn't matter if you are modifying a static schema or a dynamic one.


> But I think the more complicated of a transformation you need, the less of a difference there is -- once you start writing a lot of code it doesn't matter if you are modifying a static schema or a dynamic one.

I agree with your general points but disagree with this. Since SQL provides excellent tools for set operations and integrity constraints even very complex migrations are simpler if you have SQL + a schema. SQL features like temporary tables, window functions, inserts using a select as source, CTEs, all help out when doing the really tricky transformations.

Th exception is of course if you have millions of rows of data which you need to do a complex migration for. Then I do not think it ever can be easy, schema or not.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: