- [Instructor] So I need to fix a problem with this project,
right now if I add another meeting,
you'll notice that what I actually get
is two copies of the meetings,
and sometimes I get even more,
so what's happening is
that when I'm reading the meeting information,
I'm pushing it directly into meetings,
and if I do another entry,
then it just copies the entire new snapshot
at the end of the previous list.
So the way I'm going to fix that is
by creating a temporary variable here,
and I'm going to call this snapData,
initialize it to an empty array,
and then push the meetings into snapData
instead of into the meetings array.
And then,
after I'm done reading all that information,
then I will push the information into the meeting,
so this meetings equals snapData.
Oops, so it should be,
snapData,
so let's check this out.
And,
actually this just needs to be snapData right here.
So that's going to push the meetings,
and then when I add a new one,
then I'm only going to get the extra meeting
and not everything else.
So another thing that you'll notice here
is that it might be really good to have these sorted.
And firebase does provide some methods for sorting,
but they're not exactly that great all the time.
So if you want to, once you receive a collection,
you can run an order by,
and then you can specify how you want to order these.
So I'm going to say order by name.
And it's going to reread this list,
however, you may notice that the order isn't exactly perfect
it's actually pretty bad,
'cause you see the lowercase letters here,
arrive after the uppercase letter.
Which isn't really good.
So you can also do a limit,
so you can say order by name,
and then say limit(3),
and there are some other functions that you can use,
but I just wanted to show you that
they're not particularly useful always,
especially this order by,
because it's not case sensitive,
and there's not a good way to making that case insensitive.
So we're going to have to use old fashioned
JavaScript to take care of this .
When we receive the meetings information
or when we're pushing it into snapData,
we're going to use a regular JavaScript sort method
to sort the data here.
So we'll create two variables.
And we will compare the two pieces
of data that we get to each other,
and just sort like we would in JavaScript.
So this would be if a.name,
and then we'll use a toLoweCase method from JavaScript
is less than b.name, also toLowerCase.
Then return minus one,
and actually this parenthesis should be right here.
Else, return one.
And let's go ahead and save that.
And now you can see that our data is sorted properly.
And so sometimes you do have to use some regular JavaScript.
I think that as the firebase database
or the Firestore database improves,
you're going to probably see that issue fixed.
But for right now we have to get our hands dirty
and just do straight JavaScript.