Add new field or change the structure on all Firestore documents

前端 未结 5 701
感动是毒
感动是毒 2021-02-02 13:11

Consider a collection of users. Each document in the collection has name and email as fields.

{
  \"users\": {
    \"uid1\         


        
5条回答
  •  梦如初夏
    2021-02-02 13:15

    You fell into a gap of NOSQL databases: Document oriented databases do not guarantee structural integrity of the data (as RDBMS do)

    The deal is:

    • in an RDBMS all stored data have the same structure at any given time (within the same instance or cluster). When changing the structure (ER-diagram) you have to migrate the data for all existing records which costs time and effort.

      In result you application can be optimised for the current version of the data structure.

    • in a Document oriented database each record is an independent "Page" with its own independent structure. If you change the structure it only applies to new documents. So you don't need to migrate the existing data.

      In result you application must be able to deal with all versions of your data structure you ever used in your current database.

    I don't know about firebase in detail but in general you never update a document in a NOSQL database. You only create a new version of the document. So even if you update all documents your application must be prepared to deal with the "old" data structure...

提交回复
热议问题