Firebase tips(Database:javascript 2)

# FIREBSE TIPS

## Data

```json
{
  "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.

```js
    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](https://qiita-image-store.s3.amazonaws.com/0/199460/00aadcce-eb15-b064-3f19-7d4f75e97624.png)

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

```js
    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](https://qiita-image-store.s3.amazonaws.com/0/199460/812a1ab4-bf3c-244a-c858-7c1a3651c987.png)

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

```js
    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](https://qiita-image-store.s3.amazonaws.com/0/199460/2e4eab16-33bf-cbe9-2b51-da6ee1f5bddd.png)


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

```js
    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](https://qiita-image-store.s3.amazonaws.com/0/199460/c9cd488b-75e8-bec4-e5e5-ea2cf0eb19a1.png)