Hi all, I've been trying to find the proper way to search through my Firebase database (Firestore) to find user information, but the very limited info I can find on how to do this properly seems to not work properly. Here is the code I currently have:
`func find_uid_by_username(username: String) -> String:
var query: FirestoreQuery = FirestoreQuery.new()
query.from("user_data")
query.where("username", FirestoreQuery.OPERATOR.EQUAL, username)
#query.limit(1) # no where filter yet
var results: Array = await Firebase.Firestore.query(query)
print("Results: ",results)
if results.is_empty():
print("No documents")
else:
print("Docs:", results[0].data["username"])
return "doc.doc_name"`
If I input "test2" as the username, I expect it should be returning information about the account that has "test2" as their username, but instead I seem to be getting null errors. The only thing I can think of is that I am not properly querying the database, but I can't find any information that would show me a different way to do it.
The current data structure in the Firestore database for the user_data collection:
data
eyes: "Female_Eyes_01
hair: Female_Hair_01
username: "test2"
The error I am getting is triggering before I get the info back on the "results" variable. Its triggering this function in the Firebase scripts:
`func query(query : FirestoreQuery) -> Array:
if query.aggregations.size() > 0:
Firebase._printerr("Aggregation query sent with normal query call: " + str(query))
return []
var task : FirestoreTask = FirestoreTask.new()
task.action = FirestoreTask.Task.TASK_QUERY
var body: Dictionary = { structuredQuery = query.query }
var url: String = _base_url + _extended_url + query.sub_collection_path + _query_suffix
task.data = query
task._fields = JSON.stringify(body)
task._url = url
_pooled_request(task)
return await _handle_task_finished(task)`
Its the very last line that gets the error. And the error is:
Trying to return value of type “Nil” from a function whose return type is “Array”.
Which is what is leading me to believe that I am not getting info from the database, which would mean I am getting the data incorrectly.