1

Im new with firestore and nosql, i have this structure..

What I am trying to do is to write a query where I can filter documents based on 'exercise_id' within a map inside the 'exercises' array. How would I go about doing this, I have had a look at firestore documentation with no avail. Is this even possible? Or is my structure wrong here...

Any help is appreciated. Thanks!

{
  "end_time": "2022-11-21T23:58:21.631441",
  "exercises": [
    {
      "bar_type": null,
      "exercise_id": "chin_up_assisted",     <----- This one here
      "exercise_name": "Chin Up (Assisted)",
      "notes": [],
      "sets": [
        {
          "done": true,
          "exercise_id": "chin_up_assisted",
          "reps": 8,
          "rpe": 7.5,
          "set_type": null,
          "weight": 68,
          "weight_measure": "metric"
        },
        {
          "done": true,
          "exercise_id": "chin_up_assisted",
          "reps": 6,
          "rpe": 9,
          "set_type": null,
          "weight": 61,
          "weight_measure": "metric"
        },
        {
          "done": true,
          "exercise_id": "chin_up_assisted",
          "reps": 4,
          "rpe": 9.5,
          "set_type": null,
          "weight": 61,
          "weight_measure": "metric"
        },
        {
          "done": true,
          "exercise_id": "chin_up_assisted",
          "reps": 5,
          "rpe": 9.5,
          "set_type": null,
          "weight": 68,
          "weight_measure": "metric"
        },
        {
          "done": true,
          "exercise_id": "chin_up_assisted",
          "reps": 4,
          "rpe": 10,
          "set_type": null,
          "weight": 68,
          "weight_measure": "metric"
        }
      ],
      "total_reps": null,
      "total_volume": null,
      "weight_measure": null,
      "weight_reps": null
    },
    {
      "bar_type": null,
      "exercise_id": "triceps_dip_assisted",
      "exercise_name": "Triceps Dip (Assisted)",
      "notes": [],
      "sets": [
        {
          "done": true,
          "exercise_id": "triceps_dip_assisted",
          "reps": 8,
          "rpe": 9,
          "set_type": null,
          "weight": 68,
          "weight_measure": "metric"
        },
        {
          "done": true,
          "exercise_id": "triceps_dip_assisted",
          "reps": 7,
          "rpe": 9.5,
          "set_type": null,
          "weight": 61,
          "weight_measure": "metric"
        },
        {
          "done": true,
          "exercise_id": "triceps_dip_assisted",
          "reps": 6,
          "rpe": 9.5,
          "set_type": null,
          "weight": 61,
          "weight_measure": "metric"
        },
        {
          "done": true,
          "exercise_id": "triceps_dip_assisted",
          "reps": 7,
          "rpe": 9.5,
          "set_type": null,
          "weight": 68,
          "weight_measure": "metric"
        }
      ],
      "total_reps": null,
      "total_volume": null,
      "weight_measure": null,
      "weight_reps": null
    },
  ],
  "name": null,
  "notes": null,
  "owner": "vSq2Xp2y6GcnUA0yLBAtJcAnSbs1",
  "start_time": "2022-11-21T23:28:46.161313",
  "total_reps": null,
  "total_volume": null,
  "weight_reps": null
}

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
rsharma
  • 169
  • 1
  • 10
  • 1
    No, it's not possible to filter on an object property within an array. You will have to restructure your data to support the query. – Doug Stevenson Nov 21 '22 at 14:25

0 Answers0