0

There's a collection with 100.000 documents. Only 10 of them must have additional property that is not necessary for other documents (e.g. list of departments with only top ones have property 'Location'); As far as I understand both approaches should work just fine, but which one is preferable since using noSql db:

  1. add one more collection with documents that have 2 property: DepartmentId, Location.
  2. add property 'Location' to only selected documents, so others won't have it.
Anton
  • 1,898
  • 3
  • 18
  • 27

1 Answers1

1

The problem you are facing is well known. You have the same with source code for example.

When you are updating a piece of code, do you save it as User.js, User2.js, User3.js ... ?

Or do you use a versionning system like git and have an unique User.js?

Translating the git analogy to your issue, you should update the current data.


In mongodb you actually have two choice to perform the update.

  • Update the model in your code, and update every entry in database to match the new model.

  • Create a new model that will apply to new entries, and still have the old model to handle old formatted data.

use-more-than-one-schema-per-collection-on-mongodb

Orelsanpls
  • 22,456
  • 6
  • 42
  • 69
  • 1
    I'm only going to add documents to collection, now it's just planning. So two schema (document types) can be added to one collection with no additional steps (like additional indexing or smth)? – Anton Sep 13 '17 at 12:38
  • 1
    No additional step exactly. This is one of the best strength of nosql database. The modularity/evolutivity. – Orelsanpls Sep 13 '17 at 12:50