Retrieve data from a firebase realtime database with JavaScript

แชร์
ฝัง
  • เผยแพร่เมื่อ 5 พ.ย. 2024

ความคิดเห็น • 72

  • @-GrandhiSiddu
    @-GrandhiSiddu ปีที่แล้ว +1

    Bro your video was helped me lot thanks

  • @KevinManda
    @KevinManda 2 ปีที่แล้ว +2

    This helped me a lot but I have a question
    How can we display filtered results within the HTML?
    like instead of the console pulling all the data from the database cant we filter it to just 1-3 results within a child node?

  • @supercarsnft8842
    @supercarsnft8842 ปีที่แล้ว +1

    What security rules i have to take at showing apikey and others variables in script

    • @WadieMendja
      @WadieMendja  ปีที่แล้ว

      There're no security rule that can hide or disable access to the API key from the client side however you can add an "auth" security rule so that only the authenticated user can be able to manipulate the selected data (his data only): firebase.google.com/docs/rules/rules-and-auth
      Alternative:
      If you don't want your API key to be accessed from the client side you should consider using firebase on the server side, if you're using NodeJS you can just run the command 'npm install firebase' and you can start from there. Here is a source that might be useful for your need: firebase.google.com/docs/admin/setup

  • @dumpmail1725
    @dumpmail1725 ปีที่แล้ว +1

    Helped me a lot thnx man

  • @valentino6942
    @valentino6942 2 ปีที่แล้ว +2

    It reports me an error: "Uncaught SyntaxError: Unexpected token '

    • @debottombose4064
      @debottombose4064 ปีที่แล้ว

      Edit[ i was doing the same thing maybe you are using ' ' where you supposed to use ` ` ]

  • @SNOOPY-GAMING-INFO
    @SNOOPY-GAMING-INFO ปีที่แล้ว

    Hello i want to make a user data store so many peoples and whe the user logins that data want to see and he can change the data

  • @prabingautam421
    @prabingautam421 2 ปีที่แล้ว +1

    Help, on the console, it gives the error "firebaseRef.once is not a function"

    • @WadieMendja
      @WadieMendja  2 ปีที่แล้ว

      make sure you imported the firebase-app and the firebase-database.js at the head of your html file in your app before you execute and try :
      firebaseRef.once('value', function(snapshot) { alert(snapshot.val()); });

    • @prabingautam421
      @prabingautam421 2 ปีที่แล้ว

      @@WadieMendja I think they updated this, there is now an onValue() function that achieves the function of .once earlier

    • @pprraajjwal
      @pprraajjwal 2 ปีที่แล้ว

      @@prabingautam421 working fine

    • @pprraajjwal
      @pprraajjwal 2 ปีที่แล้ว +1

      @@WadieMendja I tried it works fine Thankyou Great job

  • @zironaquino8439
    @zironaquino8439 2 ปีที่แล้ว +1

    can you help me man? it says: _"firebase is not defined"_ (it's around the
    firebase.initializeApp(firebaseConfig); part of the code.
    and also:
    _Unexpected token 'export'_
    _Uncaught SyntaxError: Cannot use import statement outside a module_

    • @WadieMendja
      @WadieMendja  2 ปีที่แล้ว

      Just change the firebase versio to 7 instead of whatever version you're using.

  • @hjanesh
    @hjanesh 3 ปีที่แล้ว +1

    I want the old data to be removed when new data is retrieved, what should I do?

    • @WadieMendja
      @WadieMendja  3 ปีที่แล้ว +1

      You can try something like that:
      async function reatrieveThenRemove() {
      const ref = firebase.database().ref('DATA_REF');
      await ref.once('value', (snapshot)=>{
      const data = snapshot.val();
      // do something with data
      });
      // remove it
      ref.remove();
      }

  • @nghiadang391
    @nghiadang391 4 ปีที่แล้ว +1

    i have data structure like this :
    gps/ node1 ; the node1 contains latitude and longitude value. How can I retrieve that ? Help me pls

    • @WadieMendja
      @WadieMendja  4 ปีที่แล้ว +1

      // fist create the reference
      var ref = firebase.database().ref("gps");
      // Read gps object
      ref.once('value', function(snap){
      // iterate through the object
      // to read all the data inside
      snap.forEach((data)=>{
      console.log(data.val());
      })
      });
      // that's pretty much it
      // hope it's helpful

    • @nghiadang391
      @nghiadang391 4 ปีที่แล้ว

      @@WadieMendja tks you

  • @pprraajjwal
    @pprraajjwal 2 ปีที่แล้ว +1

    Great job man!

  • @janpersonawa-ao4744
    @janpersonawa-ao4744 2 ปีที่แล้ว +1

    Good day sir how can i get only one data from firebase

    • @WadieMendja
      @WadieMendja  2 ปีที่แล้ว

      you just need to specify the path of the data that you're trying to retrieve on the ref(@param) method, for instance if wanted to retrieve just a specific email I would replace ref("emails") with ref("emails/EMAIL_KEY") which is gonna retrieve only the email that I need not the hole emails object.

  • @samthomas7804
    @samthomas7804 2 ปีที่แล้ว +1

    Is there any prior use of api key in retrieving in this stage?

    • @WadieMendja
      @WadieMendja  2 ปีที่แล้ว

      What you're trying to do ?

  • @theunfinishedbusiness2407
    @theunfinishedbusiness2407 3 ปีที่แล้ว +1

    hi sir you know how can i specify the data to retrieve like not all of it just one element from the database ?

    • @WadieMendja
      @WadieMendja  3 ปีที่แล้ว +1

      Yes, you can specify the element that you wanna retrieve using the ref() method.
      Example:
      // specifying data location
      const dataRef = firebase.database().ref('/node/child/DataKey');
      // retrieving data
      dataRef.once('value', (snap)=>{const data = snap.val();});
      // But if you gave your data a random key (you used the push() method to store it) then you're gonna be forced to loop through all the elements of the node then filter it to get the data that you want.

  • @urnotalone69
    @urnotalone69 ปีที่แล้ว

    is it so hard for you to give the source code?

  • @noahnyman4420
    @noahnyman4420 ปีที่แล้ว +1

    Uncaught ReferenceError: firebase is not defined

    • @WadieMendja
      @WadieMendja  ปีที่แล้ว

      You must include firebase-app.js into you project by adding the CDN script at the HTML file or an import statement if you're using nodejs.

  • @boringblobking3783
    @boringblobking3783 3 ปีที่แล้ว +1

    this helped so much

  • @envplayz
    @envplayz 3 ปีที่แล้ว +1

    i have an problem it comes like
    [object Object]
    [object Object]
    [object Object]
    [object Object]

    • @WadieMendja
      @WadieMendja  3 ปีที่แล้ว

      Yes, because you're not specifying the object's attribute that you wanna display, you can try something like that:
      .
      For example: obj.name or obj.age ..etc

    • @envplayz
      @envplayz 3 ปีที่แล้ว

      @@WadieMendja i tried that but i thought nvm i will do something else

    • @envplayz
      @envplayz 3 ปีที่แล้ว +1

      @@WadieMendja so do u know how to check if data is a firbase child value is "1"?
      ex. user{
      verified:0
      account_banned:1
      }
      in this case see if account_banned == 1
      thx if u can help me!

    • @WadieMendja
      @WadieMendja  3 ปีที่แล้ว +1

      It should be something like that:
      const ref = firebase.database().ref("/user");
      ref.once("value", (snap)=>{
      const data = snap.val();
      if ( data.account_banned == 1 ) {
      // Do something
      }
      });

    • @envplayz
      @envplayz 3 ปีที่แล้ว

      @@WadieMendja THX i will try and reach out to u :)

  • @xzecxeed2548
    @xzecxeed2548 3 ปีที่แล้ว +1

    bro I fucking love you

  • @araju55
    @araju55 2 ปีที่แล้ว +1

    Do you know how to do that for a html map?

    • @WadieMendja
      @WadieMendja  2 ปีที่แล้ว

      you could apply the same steps on the video if you have access to the app that you're displaying on the component.

  • @ayaanahmed2650
    @ayaanahmed2650 2 ปีที่แล้ว +1

    it didnt work for me)':

    • @WadieMendja
      @WadieMendja  2 ปีที่แล้ว +1

      What type of error you getting ?

  • @tarekahmed8388
    @tarekahmed8388 3 ปีที่แล้ว +1

    Thank you 🥰🥰🥰

  • @conceicaoneves234
    @conceicaoneves234 2 ปีที่แล้ว

    firebase is not defined

  • @diegolozano8539
    @diegolozano8539 3 ปีที่แล้ว +1

    Great video, but I have the mistake, where my data shows as a :[object Object]
    I think it might be because my child in firebase is not a single element as yours (only emails).
    Can you help me, please?

    • @WadieMendja
      @WadieMendja  3 ปีที่แล้ว

      Yes, you're getting this prbl because you didn't specify the attribute, for example obj_name.email or obj_name.username ...etc

    • @diegolozano8539
      @diegolozano8539 3 ปีที่แล้ว +1

      @@WadieMendja Thanks for replying!!, i have to declare the objects inside the function snapshot? or can you tell me where do i have to do it, than you!

    • @WadieMendja
      @WadieMendja  3 ปีที่แล้ว +1

      @@diegolozano8539 yes, store the snapshot.val() object in a variable (data for example) and let's say that the data object has a property called name, now you can get the value of the property as following: data.name

    • @diegolozano8539
      @diegolozano8539 3 ปีที่แล้ว +1

      @@WadieMendja Perfect, thanks :) i just suscribed

    • @diegolozano8539
      @diegolozano8539 3 ปีที่แล้ว +2

      Sorry for keep asking, if I declare the function "var data=snapshot.val();", then i have to delete the function "element"? (the one we saw on the video") I'm asking because I don't understand how to retrieve the property ex:data.name

  • @fatehitahaamine9819
    @fatehitahaamine9819 3 ปีที่แล้ว

    Thank you Bro ❤😍

    • @WadieMendja
      @WadieMendja  2 ปีที่แล้ว

      you're welcome at anytime, hafdaQ Amine

  • @eshalali1131
    @eshalali1131 2 ปีที่แล้ว +1

    i got error sir please help me
    [object Object]
    [object Object]
    [object Object]

    • @WadieMendja
      @WadieMendja  2 ปีที่แล้ว

      Yes, because you're not specifying the object's attribute that you wanna display, you can try something like: .