In my document, there is a map referred to as "map" with a specific structure:
-document
-map
{id: number}
{id2: number2}
When the function first executes, only the document exists and I need to create the map with an initial entry.
Before the first execution:
-document
After the first execution:
-document
-map
{id: number}
Subsequent executions with an id will increment the stored number in the map. If the id does not exist in the map, it will be inserted.
For example, executing it with id2 would result in the initial structure shown above.
await admin.firestore().runTransaction(async t => {
const documentDb = await admin.firestore().doc(`document/${documentId}`).get()
const document = documentDb.data()!
if (document.map === undefined || document.map[id] === undefined) {
const tempMap = {};
tempMap[id] = 1
document.map = tempMap
} else {
document.map[id] = document.map[id] + 1
}
t.update(documentDb.ref, document);
}
This approach seems simple, but it encounters issues during compilation, specifically at tempMap[id] = 1
due to an implicit "any" type in Typescript. Is there a way to resolve this issue?