Hey all,
I seem to be running into trouble when adding data to a collection in Firestore with Python.
This is part of my transfer from RTDB to Firestore. I exported data from RTDB in JSON and I'm looping through the JSON file with Python to add to Firestore.
Now everything else gets added just fine, except when I try to add a list(array) to my collection. They're getting added as binary blobs instead of strings in an array.
It's for a list of tags. My current json field is quite dirty and needs to be cleaned up before being added to Firestore. So for example I have something like this:
"tags": "Group, Inexpensive, Outdoors,"
I need to break up that field by ","
Then looping through those results I strip the whitespace and add to a new clean list:
cleaned_tags = []
for t in tags:
t.strip()
cleaned_tags.append(t)
Then I try and add it with the rest of my data:
data = {
"name":name,
"description":description,
"tags":cleaned_tags
}
db.collection("ideas").add(data)
This adds the new document with name and description being correct. My tags field will be an array but the items in the array are binary blobs instead of strings.
I've also tried explicitly converting to strings just to see what would happen:
cleaned_tags.append(str(t))
and
data = {
"name":name,
"description":description,
"tags": str(cleaned_tags)
}
and converting to list:
data = {
"name":name,
"description":description,
"tags": list(cleaned_tags)
}
I've also tried creating a new list and adding the cleaned_tags by index as a test (there could be more than 2 items, just wanted to see what would happen):
new_new_list = [cleaned_tags[0],cleaned_tags[1]]
data = {
"name":name,
"description":description,
"tags": new_new_list
}
and also making sure that they're unicode:
cleaned_tags.append(t.encode("utf-8"))
Every time they're added as binary blobs.
Am I missing something? Or is this some kind of bug? I've been working off of this
guide regarding data types and adding data.