0

this my table structure

Chats:
-LwNV3HExAT2HR44dgJk
  hotel_id: "43"
  isseen: "false"
  message: "hello"
  receiver: "8"
  sender: "4"
  time: "31/11/2019 00:00:00"
-LwNOpLvg6bPvXGFhfJk
  hotel_id: "44"
  isseen: "false"
  message: "hello"
  receiver: "8"
  sender: "5"
  time: "01/12/2019 00:00:00"

i want to update value of isseen to true when i click on the button and call the function SetSeen()


isseen is updated when the "sender" is equal to 5 / and "hotel_id" equal to 44 / and "receiver" is equal to 8


i just do one of this condition "sender"="5" in my function as below

  SetSeen = () => {

    var db = firebase.database();
    var query = db.ref("Chats").orderByChild("sender").equalTo("5");
    query.on("child_added", function (snapshot) {
      snapshot.ref.update({ isseen: "true" })
    });
  }

and i don't have a solution to pass the other conditions ,Can somebody help me please

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
ch mariem
  • 67
  • 1
  • 6

1 Answers1

1

You cannot do multiple queries in, Firebase realtime database. To be able to solve this, you can create a common attribute in the database fro example:

Chats:
-LwNV3HExAT2HR44dgJk
  hotel_id: "43"
  isseen: "false"
  message: "hello"
  receiver: "8"
  sender: "4"
  send_isseen_hotel : "5_false_44"
  time: "31/11/2019 00:00:00"
-LwNOpLvg6bPvXGFhfJk
  hotel_id: "44"
  isseen: "false"
  message: "hello"
  receiver: "8"
  sender: "5"
  send_isseen_hotel : "5_false_44" 
  time: "01/12/2019 00:00:00"
SetSeen = () => {

    var db = firebase.database();
    var query = db.ref("Chats").orderByChild("send_isseen_hotel").equalTo("5_false_44");
    query.on("child_added", function (snapshot) {
      snapshot.ref.update({ isseen: "true" })
    });
  }
Peter Haddad
  • 78,874
  • 25
  • 140
  • 134