Reputation: 588
I am writing a Google Cloud Function that receives a Webhook JSON payload, parses the JSON and writes the data to the Cloud Firestore.
I have a map of strings inside of Cloud Firestore at collection.("orders").doc():
customerNote (map)
customerNote1 (string)
customerNote2 (string)
customerNote3 (string)
For a simple string, the syntax for writing to the Cloud Firestore within Cloud Functions could like like:
await admin.firestore().collection("orders").doc().set({
orderNameInFirestore: data.orderNamefromJSON
})
What does this cloud function look like for a Map of Strings?
Upvotes: 0
Views: 150
Reputation: 26333
Firestore can accept and store arbitrary JavaScript objects (with some limitations). As an example:
const myMap = {"key-one": "abc", "key-two": 123};
await admin.firestore().collection("orders").add({
mappedData: myMap
});
the above will work just fine so long as the map is of reasonable size.
Upvotes: 1