Describe the bug
when trying to retrieve an integer from a firestore document via document.get_value()
the returned type is String
when trying to retrieve a array from a firestore document via document.get_value()
the returned type is Dictionary and the dictionary is basically the raw document
To Reproduce
Example code to reproduce bug
extends Node2D
func _ready() -> void:
Firebase.Auth.login_succeeded.connect(on_login_succeeded)
if not Firebase.Auth.check_auth_file():
var provider: AuthProvider = Firebase.Auth.get_GoogleProvider()
Firebase.Auth.get_auth_localhost(provider, 8060)
func on_login_succeeded(auth):
Firebase.Auth.save_auth(auth)
var collection: FirestoreCollection = Firebase.Firestore.collection("test")
var test_data = {
"test_string": "this is a string for testing",
"test_int": 1234,
"test_float": 98.76,
"test_array": ["string_a", "string_b"],
"test_dict": {"key_a": "value_a", "key_b": 0.123, "key_c": 1234}
}
var doc_name: String = "test_document"
await collection.add(doc_name, test_data)
var document = await collection.get_doc(doc_name)
print(document)
for key in document.keys():
var value = document.get_value(key)
print("Key: %s" % key)
print("Type: %s" % type_string(typeof(value)))
print("Value: %s" % value)
print("")
as you can see, the test_int type is somehow a string and the test_arraytype is a dictionary which is derived fo the raw contents of the document.
also the integer is stored as a string with quotation marks
"test_int": { "integerValue": "1234" }
Edit
as it seems the problem with the array is an easy fix.
in the Utilities.gs file is this piece of code
static func from_firebase_type(value : Variant) -> Variant:
if value == null:
return null
if value.has("mapValue"):
value = fields2dict(value.values()[0])
#this is missing in the main code so i just added this and now it can retrieve the array
#if value.has("arrayValue"):
# value = fields2array(value.values()[0])
elif value.has("timestampValue"):
value = Time.get_datetime_dict_from_datetime_string(value.values()[0], false)
else:
value = value.values()[0]
Describe the bug when trying to retrieve an integer from a firestore document via document.get_value() the returned type is String
when trying to retrieve a array from a firestore document via document.get_value() the returned type is Dictionary and the dictionary is basically the raw document
To Reproduce
Example code to reproduce bug
Current output
Expected output
as you can see, the test_int type is somehow a string and the test_arraytype is a dictionary which is derived fo the raw contents of the document. also the integer is stored as a string with quotation marks
Edit as it seems the problem with the array is an easy fix. in the Utilities.gs file is this piece of code