How to remove data that was pushed in a list in Firebase? -
given
var messagelistref = new firebase('https://samplechat.firebaseio-demo.com/message_list'); messagelistref.push({ 'user_id': 'fred', 'text': 'yabba dabba doo!' });
how remove added data { 'user_id': 'fred', 'text': 'yabba dabba doo!' }
later firebase? there clean , simple way that?
i able find data again later , remove it, assuming don't know unique id generated, can't new firebase('https://samplechat.firebaseio-demo.com/message_list/'+uniqueid).remove()
(and don't know if practice). in idea first query data don't know how can list of data. example, able remove data ondisconnect.
on page https://www.firebase.com/docs/web/api/firebase/push.html, seems "see lists of data" not yet written. in roadmap add such remove lists of data?
when call push
returns new node. keep list of messages user added in memory:
var mymessagekeys = []; // put somewhere "globally"
and whenever add message:
var newmessageref = messagelistref.push({ 'user_id': 'fred', 'text': 'yabba dabba doo!' }); mymessagekeys.push(newmessageref.key());
personally feels hacky me. prefer use query, example if fred disconnects you'd like:
var mymessages = messagelistref.orderbychild('user_id').equalto('fred'); mymessages.on('value', function(messagessnapshot) { messagessnapshot.foreach(function(messagesnapshot) { messagesnapshot.ref().remove(); }); });
Comments
Post a Comment