Sign in
Log inSign up

How do you update schema changes in MongoDB

Williams Isaac's photo
Williams Isaac
·Dec 17, 2016

As we all know that database schemas is open to updates and changes as app becomes more large, i cant really find any help on updating schemas for my application. Coming from Relational database background, Its easy to add column to an existing table, but as for mongodb, i really cant figure out what to do.

Lets say in a case where a collection has the following schema

    accounts: {
        name: John Doe,
        active: 0,
        suspended: 0
        }

then i already have over 3000 exsiting and active accounts. But i need to know the defaulted ones and add split name to firstname, lastname. This is what the new schema will look like

        accounts: {
        firstname: John,
        lastname: Doe,
        email: ,
        active: 0,
        suspended: 0,
        defaulted: 0
        }

How do i go about this changes for all users ?