Odium
Odium

Reputation: 87

Firestore - Adding a new field sets it as "map"

I'm trying to add a new field inside my document.
When I'm setting it, it sets the field as string (what I need)
But when I'm trying to add something new (update), it sets it as map enter image description here

Code:

await firestore().collection(groupID).doc('images').collection(licenseNumber).doc('images')
.get()
.then((docSnapshot) => {
    if (docSnapshot.exists) {
        getImages();
        firestore().collection(groupID).doc('images').collection(licenseNumber).doc('images')
            .update({
                // [length]: reference.child(response.assets[0].fileName).fullPath,
                [response.assets[0].fileName.toString()]: reference.child(response.assets[0].fileName).fullPath,
            })
            .then(() => {

                setIsLoading(false);
            })
    } else {
        getImages();
        firestore().collection(groupID).doc('images').collection(licenseNumber).doc('images')
            .set({
                // [length]: reference.child(response.assets[0].fileName).fullPath,
                [response.assets[0].fileName.toString()]: reference.child(response.assets[0].fileName).fullPath,
            })
            .then(() => {
                setIsLoading(false);
            })
    }
})

I don't know where is the problem. Maybe It's a stupid mistake or typo.

Upvotes: 0

Views: 122

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 598817

That is expected behavior: when you have a . in the field name when updating a document, that dot is interpreted as indicated a path to a subfield. Such a mapping is not done when you call set.

So one option is to call set with merge: true to get the updating behavior in an operation that doesn't parse the ..

Alternatively you can construct a FieldPath object and pass that to update, in which case the . will (should?) be ignored there too.

Upvotes: 1

Related Questions