Home > Net >  get all users' table values with special row value, firebase web database
get all users' table values with special row value, firebase web database

Time:12-24

i have this database:

users:                   get(ref(db, `users/${db_uname}/game`)).then((snapshot) => {
  000:                     if (!(snapshot.exists())) {
    game:                    set(ref(db, `users/${db_uname}/game`), {
      cord_x: 0                cord_x: 0,
      cord_y: 0                cord_y: 0
      online: true           });
    password: "000"         }
                            update(ref(db, `users/${db_uname}/game`), {
                              online: true
                            });
                            var con = true;
                            window.db_con = con;
                          });

And i need to get username, game/cord_x, game/cord_y from all users with game/online == true, to call a function with them later. Please help! :(

function getUsers() {
  get(child(db, `users/`)).then((snapshot) => {
      (( DONT KNOW HOW ))
      create_hero(name, x, y);
    })
  });
}

CodePudding user response:

To get the db_uname, cord_x and cord_y for all nodes from your data structure, you can do:

get(child(db, `users/`)).then((snapshot) => {
    snapshot.forEach((userSnapshot) => {                    //            
  • Related