0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Firebase tips(Database:javascript 2)

Last updated at Posted at 2017-09-25

FIREBSE TIPS

Data

{
  "coffeeandcode-japan" : {
    "room" : {
      "A" : {
        "calories" : 5,
        "carbohydrate" : 0,
        "cholesterol" : 0,
        "detail" : "Lightly roasted coffee that's soft, mellow and flavorful. Easy-drinking on its own and delicious with milk, sugar or flavored with vanilla, caramel or hazelnut.",
        "id" : 1,
        "name" : "Blonde Roast",
        "protein" : 1,
        "sodium" : 10,
        "totalfat" : 0
      },
      "B" : {
        "calories" : 110,
        "carbohydrate" : 10,
        "cholesterol" : 15,
        "detail" : "A one-to-one mix of fresh brewed coffee and steamed milk add up to one distinctly delicious coffee drink.",
        "id" : 2,
        "name" : "Caffe Misto",
        "protein" : 7,
        "sodium" : 100,
        "totalfat" : 4
      },
      "C" : {
        "calories" : 10,
        "carbohydrate" : 0,
        "cholesterol" : 0,
        "detail" : "A coffee made for you in a way that showcases the nuances of every cup.",
        "id" : 3,
        "name" : "Clover(R) Brewed Coffee",
        "protein" : 1,
        "sodium" : 10,
        "totalfat" : 0
      },
      "D" : {
        "calories" : 5,
        "carbohydrate" : 0,
        "cholesterol" : 0,
        "detail" : "Our signature medium roasted coffee with a smooth, balanced and rich flavor, minus the caffeine.",
        "id" : 4,
        "name" : "Decaf Pike Place(R) Roast",
        "protein" : 1,
        "sodium" : 10,
        "totalfat" : 0
      },
      "E" : {
        "calories" : 5,
        "carbohydrate" : 0,
        "cholesterol" : 0,
        "detail" : "This full-bodied dark roast coffee has the bold, robust flavors to showcase our roasting and blending artistry.",
        "id" : 5,
        "name" : "Featured Dark Roast",
        "protein" : 1,
        "sodium" : 10,
        "totalfat" : 0
      }
    },
    "user" : {
      "eFcFmn2lbqTzXf83vtHPdSCID9W2" : {
        "id" : 1,
        "name" : "coffee"
      }
    }
  }
}

1. Retrieve data, calories item of which equals to 5.

    database.ref('/coffeeandcode-japan/room').orderByChild('calories').equalTo(5).once('value').then(
        (snapshot) => {
          snapshot.forEach((data)=> {
            console.log("id: " + data.val().id + " name: " + data.val().name);
          });
        }
      );

result
result.png

2. Retrive data, calroies item of which is more than 10.

    database.ref('/coffeeandcode-japan/room').orderByChild('calories').startAt(10).once('value').then(
        (snapshot) => {
          snapshot.forEach((data)=> {
            console.log("id: " + data.val().id + " name: " + data.val().name);
          });
        }
      );

result
result.png

3. Retrive data, calroies item of which is less than 10

    database.ref('/coffeeandcode-japan/room').orderByChild('calories').endAt(10).once('value').then(
        (snapshot) => {
          snapshot.forEach((data)=> {
            console.log("id: " + data.val().id + " name: " + data.val().name);
          });
        }
      );

result
result.png

4. Retrive data, calroies item is less than 10 and calroies item is more than 10.(equals to 10)

    database.ref('/coffeeandcode-japan/room').orderByChild('calories').endAt(10).startAt(10).once('value').then(
        (snapshot) => {
          snapshot.forEach((data)=> {
            console.log("id: " + data.val().id + " name: " + data.val().name);
          });
        }
      );

result
result.png

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?