I'm using Firebase to build an application that has two models, `A` and `B`:

* There is a one to many relationship between `A` and `B` (`A` has many `B`).
* `A` and `B` need to be somewhere easy to query, so I need a way to fetch all `A` models that have a property that fulfills a condition. Same with `B`.
* `B` has a property `createdAt` (that never changes) and a property `status` (that changes every now and then) and I want to list all `Bs` that are owned by a particular `A` and which `status` and/or `createdAt` properties fulfill some condition.
* `Bs` are private and can only be read by a user that is authenticated and can read the `A` to which they belong (User can read `b1` if can read `a1` and `a1` belongs to `b1`).

Following [Firebase guidelines](https://www.firebase.com/docs/web/guide/structuring-data.html), my first try was to do something like this:

```
"As": {
  "a1": {
    ...
    Bs: {
      "b1": true,
      ...
    },
  },
  ...
},
"Bs": {
  "b1": {
    ...,
    "status": "OPEN",
    "createdAt": 1464249410579,
  },
  ...
},

```

The problem with this solution is that to access `Bs` that belong to `a1` which status is `OPEN` and are not older than one month, I have to access `a1.Bs`, get all the id's and then access `Bs` one by one (which is fine, according to [Firebase guidelines](https://www.firebase.com/docs/web/guide/structuring-data.html)) and then filter them to find out if they fulfill my condition, which I find extremely inefficient.

Any suggestion on how to do this?