javascript - Search Firebase for Child -


i building url shortener in node.js , firebase , functioning @ moment if shorten url , gets shortened again uses link. here data in firebase looks like:

database    --> (short link)     --> (long url)     --> (views)   --> q0     --> http://google.co.uk/     --> 10   --> g7     --> http://google.co.uk/     --> 3 

i when makes new link checks existing entry. i'm not sure if in-efficient or not.

i'm not sure how go around doing grateful help. fetch long url each of entries , check them new 1 being created.

when adding shortened url can check see if exists:

dbref.once("value", function(snap) {     snap.foreach(function(shortlink) {         //let's field "long url" called "longlink"         if(newurl === shortlink.val().longlink) {             return true; //cancel loop, newurl in db         }     }); }); 

you can add flag indicates whether duplicate found or not, , add url db if nothing found based on flag.


Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -