adding data to firebase realtime database from an object (web)
I have an object containing multiple key value pairs, I want to add all the keys and their values, from inside the object to an existing node, without disturbing the data already present inside the node.
If i write like this
var ref = firebase.database().ref("hams/spam_words/");
ref.update({
new_words_ham //new_word_ham is an object containing n number of words
});
it will add new_words_ham as another child node inside the main node , i cannot have that
even using a forloop on the object does not work
var ref = firebase.database().ref("hams/spam_words/");
for(var i in new_words_ham){
var word = i
ref.update({
i
});
I am new to js as well as to firebase. Please do tell me if i have got any concept wrong
javascript firebase firebase-realtime-database
add a comment |
I have an object containing multiple key value pairs, I want to add all the keys and their values, from inside the object to an existing node, without disturbing the data already present inside the node.
If i write like this
var ref = firebase.database().ref("hams/spam_words/");
ref.update({
new_words_ham //new_word_ham is an object containing n number of words
});
it will add new_words_ham as another child node inside the main node , i cannot have that
even using a forloop on the object does not work
var ref = firebase.database().ref("hams/spam_words/");
for(var i in new_words_ham){
var word = i
ref.update({
i
});
I am new to js as well as to firebase. Please do tell me if i have got any concept wrong
javascript firebase firebase-realtime-database
also can some one just tell me if i am using the terms node and child in the wrong sense here
– Akash
Jan 3 at 6:56
This statement looks a bit strangeref.update({ new_words_ham });
Are the wrapping curly brackets a typo or is removing them solving your problem?
– Dennis Alund
Jan 3 at 7:33
1
@DennisAlund modern JavaScript allows{ new_words_ham }
as a shorthand for{ new_words_ham: new_words_ham }
. Yes, I find it incredibly hard to get used to too. ;-)
– Frank van Puffelen
Jan 3 at 14:45
Thanks for that, I learned something interesting from this 😊
– Dennis Alund
Jan 4 at 0:30
add a comment |
I have an object containing multiple key value pairs, I want to add all the keys and their values, from inside the object to an existing node, without disturbing the data already present inside the node.
If i write like this
var ref = firebase.database().ref("hams/spam_words/");
ref.update({
new_words_ham //new_word_ham is an object containing n number of words
});
it will add new_words_ham as another child node inside the main node , i cannot have that
even using a forloop on the object does not work
var ref = firebase.database().ref("hams/spam_words/");
for(var i in new_words_ham){
var word = i
ref.update({
i
});
I am new to js as well as to firebase. Please do tell me if i have got any concept wrong
javascript firebase firebase-realtime-database
I have an object containing multiple key value pairs, I want to add all the keys and their values, from inside the object to an existing node, without disturbing the data already present inside the node.
If i write like this
var ref = firebase.database().ref("hams/spam_words/");
ref.update({
new_words_ham //new_word_ham is an object containing n number of words
});
it will add new_words_ham as another child node inside the main node , i cannot have that
even using a forloop on the object does not work
var ref = firebase.database().ref("hams/spam_words/");
for(var i in new_words_ham){
var word = i
ref.update({
i
});
I am new to js as well as to firebase. Please do tell me if i have got any concept wrong
javascript firebase firebase-realtime-database
javascript firebase firebase-realtime-database
edited Jan 4 at 8:16
Akash
asked Jan 3 at 6:56
Akash Akash
32
32
also can some one just tell me if i am using the terms node and child in the wrong sense here
– Akash
Jan 3 at 6:56
This statement looks a bit strangeref.update({ new_words_ham });
Are the wrapping curly brackets a typo or is removing them solving your problem?
– Dennis Alund
Jan 3 at 7:33
1
@DennisAlund modern JavaScript allows{ new_words_ham }
as a shorthand for{ new_words_ham: new_words_ham }
. Yes, I find it incredibly hard to get used to too. ;-)
– Frank van Puffelen
Jan 3 at 14:45
Thanks for that, I learned something interesting from this 😊
– Dennis Alund
Jan 4 at 0:30
add a comment |
also can some one just tell me if i am using the terms node and child in the wrong sense here
– Akash
Jan 3 at 6:56
This statement looks a bit strangeref.update({ new_words_ham });
Are the wrapping curly brackets a typo or is removing them solving your problem?
– Dennis Alund
Jan 3 at 7:33
1
@DennisAlund modern JavaScript allows{ new_words_ham }
as a shorthand for{ new_words_ham: new_words_ham }
. Yes, I find it incredibly hard to get used to too. ;-)
– Frank van Puffelen
Jan 3 at 14:45
Thanks for that, I learned something interesting from this 😊
– Dennis Alund
Jan 4 at 0:30
also can some one just tell me if i am using the terms node and child in the wrong sense here
– Akash
Jan 3 at 6:56
also can some one just tell me if i am using the terms node and child in the wrong sense here
– Akash
Jan 3 at 6:56
This statement looks a bit strange
ref.update({ new_words_ham });
Are the wrapping curly brackets a typo or is removing them solving your problem?– Dennis Alund
Jan 3 at 7:33
This statement looks a bit strange
ref.update({ new_words_ham });
Are the wrapping curly brackets a typo or is removing them solving your problem?– Dennis Alund
Jan 3 at 7:33
1
1
@DennisAlund modern JavaScript allows
{ new_words_ham }
as a shorthand for { new_words_ham: new_words_ham }
. Yes, I find it incredibly hard to get used to too. ;-)– Frank van Puffelen
Jan 3 at 14:45
@DennisAlund modern JavaScript allows
{ new_words_ham }
as a shorthand for { new_words_ham: new_words_ham }
. Yes, I find it incredibly hard to get used to too. ;-)– Frank van Puffelen
Jan 3 at 14:45
Thanks for that, I learned something interesting from this 😊
– Dennis Alund
Jan 4 at 0:30
Thanks for that, I learned something interesting from this 😊
– Dennis Alund
Jan 4 at 0:30
add a comment |
1 Answer
1
active
oldest
votes
Your existing code
//new_word_ham is an object containing n number of words
firebase.database().ref("hams/spam_words/").update({
new_words_ham
});
Can be rewritten as
firebase.database().ref("hams/spam_words/").update({
new_words_ham: new_words_ham
});
when the shorthand syntax is expanded. What I believe you want is simply
firebase.database().ref("hams/spam_words/").update(new_words_ham);
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54017632%2fadding-data-to-firebase-realtime-database-from-an-object-web%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Your existing code
//new_word_ham is an object containing n number of words
firebase.database().ref("hams/spam_words/").update({
new_words_ham
});
Can be rewritten as
firebase.database().ref("hams/spam_words/").update({
new_words_ham: new_words_ham
});
when the shorthand syntax is expanded. What I believe you want is simply
firebase.database().ref("hams/spam_words/").update(new_words_ham);
add a comment |
Your existing code
//new_word_ham is an object containing n number of words
firebase.database().ref("hams/spam_words/").update({
new_words_ham
});
Can be rewritten as
firebase.database().ref("hams/spam_words/").update({
new_words_ham: new_words_ham
});
when the shorthand syntax is expanded. What I believe you want is simply
firebase.database().ref("hams/spam_words/").update(new_words_ham);
add a comment |
Your existing code
//new_word_ham is an object containing n number of words
firebase.database().ref("hams/spam_words/").update({
new_words_ham
});
Can be rewritten as
firebase.database().ref("hams/spam_words/").update({
new_words_ham: new_words_ham
});
when the shorthand syntax is expanded. What I believe you want is simply
firebase.database().ref("hams/spam_words/").update(new_words_ham);
Your existing code
//new_word_ham is an object containing n number of words
firebase.database().ref("hams/spam_words/").update({
new_words_ham
});
Can be rewritten as
firebase.database().ref("hams/spam_words/").update({
new_words_ham: new_words_ham
});
when the shorthand syntax is expanded. What I believe you want is simply
firebase.database().ref("hams/spam_words/").update(new_words_ham);
answered Jan 3 at 7:33
Sami HultSami Hult
2,3871613
2,3871613
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54017632%2fadding-data-to-firebase-realtime-database-from-an-object-web%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
also can some one just tell me if i am using the terms node and child in the wrong sense here
– Akash
Jan 3 at 6:56
This statement looks a bit strange
ref.update({ new_words_ham });
Are the wrapping curly brackets a typo or is removing them solving your problem?– Dennis Alund
Jan 3 at 7:33
1
@DennisAlund modern JavaScript allows
{ new_words_ham }
as a shorthand for{ new_words_ham: new_words_ham }
. Yes, I find it incredibly hard to get used to too. ;-)– Frank van Puffelen
Jan 3 at 14:45
Thanks for that, I learned something interesting from this 😊
– Dennis Alund
Jan 4 at 0:30