Nazim Zeeshan
Nazim Zeeshan

Reputation: 733

Firebase DataStructure

I am trying to create a "Users" list. But I am not able to replicate the way it is structured in the docs https://www.firebase.com/images/data_structure.png.

Instead my structure has a Users with child nodes having some raw text. https://www.evernote.com/shard/s52/sh/21c878d6-4978-440c-a089-10da4fb6d792/2d0d7a90861ef6f94e425fdb904b8ab2 Instead I want child nodes named as 'john','terry' etc as shown in your docs.

Hope this makes sense. Thanks

Upvotes: 2

Views: 680

Answers (1)

Kato
Kato

Reputation: 40582

It looks like you're talking about the keys. In the Firebase example, the keys are things like fred, but in your data they appear as -iKvpJ...

If you insert your records using push, then Firebase automatically assigns the key:

firebase.child('users').push({ name: 'Fred' });

// /users/-KvpJ.../name/Fred

Use child and set to specify your own keys:

firebase.child('users/fred').set({ name: 'Fred' });

// /users/fred/name/Fred

Upvotes: 4

Related Questions