javascript - Firebase - Push to pushed data -


here's data

{   "deck" : {     "-jkpwaniekjqvsdtpd4m" : {       "deck" : "deck 1",       "user" : "simplelogin:1"     },     "-jkq4unexm-qwho_u2yo" : {       "deck" : "deck 2",       "user" : "simplelogin:1"     },     "-jkq5-ii1q5ym6w3ytmg" : {       "deck" : "deck 3",       "user" : "simplelogin:6"     },     "-jks5mbmhmpb9mwnnocj" : {       "deck" : "deck 4",       "user" : "simplelogin:1"     }   } } 

if want add:

      cards: {         "-generatedkey":{           "title":"foo",           "text":"bar",         }       } 

to item deck "deck 2", how select object push it. end result be:

{   "deck" : {     "-jkpwaniekjqvsdtpd4m" : {       "deck" : "deck 1",       "user" : "simplelogin:1"     },     "-jkq4unexm-qwho_u2yo" : {       cards: {         "-generatedkey":{           "title":"foo",           "text":"bar",         }       }       "deck" : "deck 2",       "user" : "simplelogin:1"     },     "-jkq5-ii1q5ym6w3ytmg" : {       "deck" : "deck 3",       "user" : "simplelogin:6"     },     "-jks5mbmhmpb9mwnnocj" : {       "deck" : "deck 4",       "user" : "simplelogin:1"     }   } } 

here tried:

  deckref.orderbychild('deckname').equalto('deck 2').push({     card: {       title: 'foo',       text: 'bar'     }   }); 

but returned error. do achieve this?

deckref.orderbychild('deckname').equalto('deck 2') returns query, not ref. query can match many nodes. though in case matches one, need first capture 1 node ref able push it.

var query = deckref.orderbychild('deckname').equalto('deck 2'); query.once('child_added', function(snapshot) {     snapshot.ref().child('cards').push({         title: 'foo',         text: 'bar'     }); }); 

Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -