I'm building a simple AngularJS app to store 2 different things under 1 thing using Firebase. Say, male
and female
student groups under students
.
This is my current Firebase data structure:
And this is my code for Add function:
$scope.add = function() {
console.log('add button clicked!');
var ref = new Firebase('https://XXX.firebaseio.com/');
var onComplete = function(error) {
if (error) {
console.log('Failed to add a new record');
} else {
console.log('Successfully add a new record');
}
};
var order = ref.child("students");
var newPostRef = order.push([{
"male": [{
"name": "Jose Fowler",
"age": 20
}, {
"name": "Earl Murray",
"age": 21
}]
}, {
"female": [{
"name": "Jessica Gomez",
"age": 22
}, {
"name": "Leona Franklin",
"age": 23
}]
}], onComplete);
var postID = newPostRef.key();
console.log("Unique ID: " + postID);
}
Since I'm new with NoSQL, I found that this data structure looks weird.
My questions:
Am I doing it right?
Does
0
s and1
s in the image is normal?If there is better way, how to improve my code so that Firebase can construct better data structure for me?
Does below structure possible?
Note: I want to have each data set has unique ID. In other words, each student in students has unique ID. I know it doesn't make sense by looking at this students
example. Sorry.