Firebase Returns Array With Undefined Object After Remove
Solution 1:
The links provided by @cartant gave the answer.
Yes, firebase does tolerates array structures in it's data but is not recommended to use them unless the specific data is not going to mutate too much or at all. In my case (creating some sort of CRUD app) is not recommendable, just use objects end everything is ok. The thing is that if you upload a json file with an array in it, firebase will transform that into an object structure using integers as the key of each element in the array. Then when I started to remove elements and reached this point:
if (!opt_exportFormat && allIntegerKeys && maxKey < 2 * numKeys) {
// convert to array.var array = [];
for (var key in obj)
array[key] = obj[key];
return array;
} else {
if (opt_exportFormat && !this.getPriority().isEmpty()) {
obj['.priority'] = this.getPriority().val();
}
return obj;
}
After deleting a specific number of elements the code passed to the else part of the statement, which ultimately result in firebase returning an object creating the whole issue.
I ended up with this type of structure:
{"users":{"user_00":{"id":0,"name":"Toma Broome"},"user_01":{"id":1,"name":"Boyd Bolens"}}}
And using lodash to loop through the object (or it could be a for in loop) I was able to get the data in the same way I was doing when using an array. Finally using an object structure I didn't got any more collections with undefined elements in it.
@cartant, thanks a lot!!! I definitely learn something with your comments. I hope that you could post an answer so I can mark it as the solution of the problem and upvote it, you earned it sir!!
Post a Comment for "Firebase Returns Array With Undefined Object After Remove"