Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. "data" : {
  2. "-LYBzlXPoN0137KRLovk" : {
  3. "-LYC-HHqDFgL9PovJiBr" : {
  4. "age" : 35,
  5. "country" : "Country",
  6. "date" : "2019-02-08T13:07:10+01:00",
  7. "gender" : "male",
  8. "id" : 1549627467620,
  9. },
  10. "age" : 35,
  11. "country" : "Country",
  12. "date" : "2019-02-08T13:04:27+01:00",
  13. "gender" : "male",
  14. "id" : 1549627467620,
  15.  
  16. exports.migrateVisits = functions.database.ref('/data/{key}/{nestedKey}')
  17. .onWrite((change:any, context:any) => {
  18. // Get a reference to the Firestore document of the changed user
  19. let userDoc = admin.firestore()
  20. .collection(`data/{key}/nestedKeys`)
  21. .doc(context.params.nestedKey);
  22. // If this user has been deleted, delete in Firestore also
  23. if (!change.after.exists()) {
  24. return userDoc.delete();
  25. }
  26. // Get the user object with the new changes,
  27. // as opposed to its value before the edit
  28. let userData = change.after.val();
  29. // Now update Firestore with that change
  30.  
  31. return userDoc.set(userData);
  32. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement