Firebase get method returning a list for one object of objects and a dict for another

Im using django with firebase and have 2 objects of objects in the database, everything about them is the same, the way i store them in the database, the way im trying to access them. When i use the get method phones = ref.child('Data').child('users').child(uid).child('phones').get() computers = ref.child('Data').child('users').child(uid).child('computers').get() (absolutely the same way) for the fisrt one i get a list of dict looking like that [{'OS': 'Windows', 'battery': 2000.0, 'memory': 16.0, 'popularity': 200.0, 'price': 2429.73, 'screen': 6.0}, {'OS': 'Windows', 'battery': 1600.0, 'memory': 32.0, 'popularity': 200.0, 'price': 1907.28, 'screen': 6.0}] and for the second one i get a dict of dict like this one
{'12': {'cd': 'no', 'hd': 5.0, 'multi': 'no', 'premium': 'yes', 'price': 1397.0, 'ram': 5.0, 'screen': 2.0, 'speed': 5.0}, '13': {'cd': 'yes', 'hd': 45.0, 'multi': 'no', 'premium': 'no', 'price': 1999.0, 'ram': 8.0, 'screen': 14.0, 'speed': 120.0}} the second one also has their id below which they are stored (i store them like that ref = db.reference("Data/users/"+str(request.session['user_id'])+'/phones/'+str( telephone = phone.save_to_firebase() ref.set(telephone), ref = db.reference("Data/users/"+str(request.session['user_id'])+'/computers/'+str( computer = comp.save_to_firebase() ref.set(computer)) i want both of them to look like the second and have no idea why they differ

I checked everything but there is not a single difference about how the objects are treated

It looks like you're storing nodes in the Firebase Realtime Database with short numeric values for their keys. This causes the Firebase SDKs to try and interpret them as arrays, which seems to work for some cases and not for others.

There is no way for you to control this behavior of the SDKs/APIs, so the best way to deal with it is to not use numeric keys, and for example prefix them bu a short string value, i.e. key_12.

For more on how Firebase deals with arrays/array-like structures, see Best Practices: Arrays in Firebase.

Back to Top