简体   繁体   中英

Model Firestore Data

I am creating a new database using Firestore. I am new to NoSQL and trying to determine best practices for modeling my data. I know that Firestore data is shallow by default (as opposed to the Realtime Database) so nesting isn't a problem. That said, what would be the best way to model a more-or-less standard user object?

Option 1 — Parent Level Only:

users {
    uid {
        name: 'Bob',
        officeNumber: 1234567890,
        faxNumber: 0987654321,
        email: 'test@test.com',
        domain: '@test.com',
        facebook: 'bobdylan97',
        twitter: 'bobbystwitter',
        instagram: 'bobinsta',
        street: '111 N Elm St',
        city: 'Brooklyn',
        state: 'NY',
        zip: 12345,
        height: 72,
        weight: 200,
        hairColor: 'brown',
        eyeColor: 'blue'
    }
}

Option 2 — Nest Multiple Levels:

users {
    uid {
        personal {
            name {
                first: 'Bob',
                last: 'Dylan'
            },
            attributes {
                height: 72,
                weight: 200,
                hairColor: 'brown',
                eyeColor: 'blue'
            }
        },
        contact {
            phone {
                office: 1234567890,
                fax: 0987654321
            },
            email: 'test@test.com',
            domain: '@test.com',
            social {
                facebook: 'bobdylan97',
                twitter: 'bobbystwitter',
                instagram: 'bobinsta'
            }
        },
        address {
            street: '111 N Elm St',
            city: 'Brooklyn',
            state: 'NY',
            zip: 12345
        }
    }
}

The company I am building this for is growing and there may be additional data added at various points, so scaling is a potential concern. Are there any problems or concerns with grouping data like in Option 2? What is the best practice for modeling data like this? Is the best practice to optimize the model for querying or for organization?

I would reccomend you to watch: What is a NoSQL Database? - Get to Know Cloud Firestore Ep.1

It perfectly explains the basic concepts of Firestore.

If you are storing users in a users collection and the uid is the document ID, then Option 2 should work fine for you.

You are only storing a fairly small amount of data about each user in a document, so you shouldn't hit the 1Mb limit. You could probably squeeze a base64 encoded profile picture in here, too, without problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM