Skip to content

Instantly share code, notes, and snippets.

@callezenwaka
Created December 9, 2021 17:52
Show Gist options
  • Save callezenwaka/c00ef64ff295c654a0fb3ac6e1e1f423 to your computer and use it in GitHub Desktop.
Save callezenwaka/c00ef64ff295c654a0fb3ac6e1e1f423 to your computer and use it in GitHub Desktop.
'use strict';
// Import packages
import admin from 'firebase-admin';
const FieldValue = admin.firestore.FieldValue;
// Add credential service account details
import serviceAccount from ".path-to-file.json";
// Initialize firebase admin sdk config
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
});
const codes = ['8034', '1146', '2423', '8744'];
const docRef = admin.firestore().collection('testing').doc('TgTjKUFs3tJCxrdnRcBj');
docRef.update("subscriptions", FieldValue.arrayUnion(...codes));
// docRef.update("subscriptions", FieldValue.arrayUnion(null, codes));
// output in firestore
subscriptions
(array)
0: "6"
(string)
1: "7"
(string)
10: "2423"
(string)
11: "8744"
(string)
2: "1"
(string)
3: "2"
(string)
4: "8"
(string)
5: "46"
(string)
6: "3"
(string)
7: "4"
(string)
8: "8034"
(string)
9: "1146"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment