Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- "data" : {
- "-LYBzlXPoN0137KRLovk" : {
- "-LYC-HHqDFgL9PovJiBr" : {
- "age" : 35,
- "country" : "Country",
- "date" : "2019-02-08T13:07:10+01:00",
- "gender" : "male",
- "id" : 1549627467620,
- },
- "age" : 35,
- "country" : "Country",
- "date" : "2019-02-08T13:04:27+01:00",
- "gender" : "male",
- "id" : 1549627467620,
- exports.migrateVisits = functions.database.ref('/data/{key}/{nestedKey}')
- .onWrite((change:any, context:any) => {
- // Get a reference to the Firestore document of the changed user
- let userDoc = admin.firestore()
- .collection(`data/{key}/nestedKeys`)
- .doc(context.params.nestedKey);
- // If this user has been deleted, delete in Firestore also
- if (!change.after.exists()) {
- return userDoc.delete();
- }
- // Get the user object with the new changes,
- // as opposed to its value before the edit
- let userData = change.after.val();
- // Now update Firestore with that change
- return userDoc.set(userData);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement