how to set value to zero of key-value pair object which i got in firebase cloud function(snapshot)
up vote
1
down vote
favorite
i have created cloud function which will trigger onCreate()
when new value is add to node Sample/Pen
.whenever the new node is created in Sample/Pen
, i wanted to create another node which is Final/Pen
but the values of key-value pair should be zero.
firebase firebase-realtime-database google-cloud-functions
add a comment |
up vote
1
down vote
favorite
i have created cloud function which will trigger onCreate()
when new value is add to node Sample/Pen
.whenever the new node is created in Sample/Pen
, i wanted to create another node which is Final/Pen
but the values of key-value pair should be zero.
firebase firebase-realtime-database google-cloud-functions
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
i have created cloud function which will trigger onCreate()
when new value is add to node Sample/Pen
.whenever the new node is created in Sample/Pen
, i wanted to create another node which is Final/Pen
but the values of key-value pair should be zero.
firebase firebase-realtime-database google-cloud-functions
i have created cloud function which will trigger onCreate()
when new value is add to node Sample/Pen
.whenever the new node is created in Sample/Pen
, i wanted to create another node which is Final/Pen
but the values of key-value pair should be zero.
firebase firebase-realtime-database google-cloud-functions
firebase firebase-realtime-database google-cloud-functions
edited Nov 10 at 10:35
PradyumanDixit
1,8311718
1,8311718
asked Nov 10 at 10:33
ninja jack
205
205
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
The following will do the job:
exports.finalPen = functions.database
.ref('/Sample/Pen/penId')
.onCreate((snap, context) =>
const createdData = snap.val(); // data that was created
return admin
.database()
.ref('Final/Pen/' + snap.key)
.set(setAllToZero(createdData));
);
const setAllToZero = function(pen)
Object.keys(pen).forEach(function(key)
pen[key] = 0;
);
return pen;
;
Thanks a lot Man, you saved my life :D
– ninja jack
2 days ago
Glad that I could help! You may also accept my answer, see stackoverflow.com/help/someone-answers. Thanks!
– Renaud Tarnec
2 days ago
Yes, i already did..:)
– ninja jack
2 days ago
I meant clicking on the grey checkmark next to the answer in such a way it becomes green :) It means that « you received an answer that worked for you personally », see stackoverflow.com/help/accepted-answer. In addition it kind of rewards the person who answered correctly by giving him some more reputation.
– Renaud Tarnec
2 days ago
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
The following will do the job:
exports.finalPen = functions.database
.ref('/Sample/Pen/penId')
.onCreate((snap, context) =>
const createdData = snap.val(); // data that was created
return admin
.database()
.ref('Final/Pen/' + snap.key)
.set(setAllToZero(createdData));
);
const setAllToZero = function(pen)
Object.keys(pen).forEach(function(key)
pen[key] = 0;
);
return pen;
;
Thanks a lot Man, you saved my life :D
– ninja jack
2 days ago
Glad that I could help! You may also accept my answer, see stackoverflow.com/help/someone-answers. Thanks!
– Renaud Tarnec
2 days ago
Yes, i already did..:)
– ninja jack
2 days ago
I meant clicking on the grey checkmark next to the answer in such a way it becomes green :) It means that « you received an answer that worked for you personally », see stackoverflow.com/help/accepted-answer. In addition it kind of rewards the person who answered correctly by giving him some more reputation.
– Renaud Tarnec
2 days ago
add a comment |
up vote
1
down vote
accepted
The following will do the job:
exports.finalPen = functions.database
.ref('/Sample/Pen/penId')
.onCreate((snap, context) =>
const createdData = snap.val(); // data that was created
return admin
.database()
.ref('Final/Pen/' + snap.key)
.set(setAllToZero(createdData));
);
const setAllToZero = function(pen)
Object.keys(pen).forEach(function(key)
pen[key] = 0;
);
return pen;
;
Thanks a lot Man, you saved my life :D
– ninja jack
2 days ago
Glad that I could help! You may also accept my answer, see stackoverflow.com/help/someone-answers. Thanks!
– Renaud Tarnec
2 days ago
Yes, i already did..:)
– ninja jack
2 days ago
I meant clicking on the grey checkmark next to the answer in such a way it becomes green :) It means that « you received an answer that worked for you personally », see stackoverflow.com/help/accepted-answer. In addition it kind of rewards the person who answered correctly by giving him some more reputation.
– Renaud Tarnec
2 days ago
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
The following will do the job:
exports.finalPen = functions.database
.ref('/Sample/Pen/penId')
.onCreate((snap, context) =>
const createdData = snap.val(); // data that was created
return admin
.database()
.ref('Final/Pen/' + snap.key)
.set(setAllToZero(createdData));
);
const setAllToZero = function(pen)
Object.keys(pen).forEach(function(key)
pen[key] = 0;
);
return pen;
;
The following will do the job:
exports.finalPen = functions.database
.ref('/Sample/Pen/penId')
.onCreate((snap, context) =>
const createdData = snap.val(); // data that was created
return admin
.database()
.ref('Final/Pen/' + snap.key)
.set(setAllToZero(createdData));
);
const setAllToZero = function(pen)
Object.keys(pen).forEach(function(key)
pen[key] = 0;
);
return pen;
;
answered Nov 10 at 13:57
Renaud Tarnec
8,63821431
8,63821431
Thanks a lot Man, you saved my life :D
– ninja jack
2 days ago
Glad that I could help! You may also accept my answer, see stackoverflow.com/help/someone-answers. Thanks!
– Renaud Tarnec
2 days ago
Yes, i already did..:)
– ninja jack
2 days ago
I meant clicking on the grey checkmark next to the answer in such a way it becomes green :) It means that « you received an answer that worked for you personally », see stackoverflow.com/help/accepted-answer. In addition it kind of rewards the person who answered correctly by giving him some more reputation.
– Renaud Tarnec
2 days ago
add a comment |
Thanks a lot Man, you saved my life :D
– ninja jack
2 days ago
Glad that I could help! You may also accept my answer, see stackoverflow.com/help/someone-answers. Thanks!
– Renaud Tarnec
2 days ago
Yes, i already did..:)
– ninja jack
2 days ago
I meant clicking on the grey checkmark next to the answer in such a way it becomes green :) It means that « you received an answer that worked for you personally », see stackoverflow.com/help/accepted-answer. In addition it kind of rewards the person who answered correctly by giving him some more reputation.
– Renaud Tarnec
2 days ago
Thanks a lot Man, you saved my life :D
– ninja jack
2 days ago
Thanks a lot Man, you saved my life :D
– ninja jack
2 days ago
Glad that I could help! You may also accept my answer, see stackoverflow.com/help/someone-answers. Thanks!
– Renaud Tarnec
2 days ago
Glad that I could help! You may also accept my answer, see stackoverflow.com/help/someone-answers. Thanks!
– Renaud Tarnec
2 days ago
Yes, i already did..:)
– ninja jack
2 days ago
Yes, i already did..:)
– ninja jack
2 days ago
I meant clicking on the grey checkmark next to the answer in such a way it becomes green :) It means that « you received an answer that worked for you personally », see stackoverflow.com/help/accepted-answer. In addition it kind of rewards the person who answered correctly by giving him some more reputation.
– Renaud Tarnec
2 days ago
I meant clicking on the grey checkmark next to the answer in such a way it becomes green :) It means that « you received an answer that worked for you personally », see stackoverflow.com/help/accepted-answer. In addition it kind of rewards the person who answered correctly by giving him some more reputation.
– Renaud Tarnec
2 days ago
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53238076%2fhow-to-set-value-to-zero-of-key-value-pair-object-which-i-got-in-firebase-cloud%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password