1

my db looks like this.

   {
  "_id": "some_location_id",
  "location_name": "columbia_mall",
  "floors": [
    {
      "_id": "some_floor_id",
      "floor_name": "1F",
      "stores": [
        {
          "_id": "some_store_id",
          "store_name": "zara",
          "items": [
            {
              "_id": "some_item_id",
              "category": "man_clthes",
            },
            {
              "_id": "some_item_id",
              "category": "woman_clthes",
            },
          ]
        },
        {
          "_id": "some_store_id",
          "store_name": "gap",
          "items": [
            {
              "_id": "some_item_id",
              "category": "man_clthes",
            },
            {
              "_id": "some_item_id",
              "category": "woman_clthes",
            },
          ]
        },
      ]
    },
    {
      "_id": "some_floor_id",
      "floor_name": "2F",
      "stores": [
        {
          "_id": "some_store_id",
          "store_name": "banana_republic",
          "items": [
            {
              "_id": "some_item_id",
              "category": "man_clthes",
            },
            {
              "_id": "some_item_id",
              "category": "woman_clthes",
            },
          ]
        },
        {
          "_id": "some_store_id",
          "store_name": "wallmart",
          "items": [
            {
              "_id": "some_item_id",
              "category": "man_clthes",
            },
            {
              "_id": "some_item_id",
              "category": "woman_clthes",
            },
          ]
        },
      ]
    },

  ]
},
{
  ...another location obj
}

I need to the followings,

  1. find the location
  2. find the floor in array within location
  3. find the store in array within the floor

Is there a way I can query? I spent hours searching the exact case as I have but failed to do so.

I was trying to expand the below query..

LocationModel.find(
  { _id: location_id },
  { floors: { $elemMatch: { _id: floor_id } } }
).then(...)

but I cannot go further to search for the store.. Can I get some help?

Johnny Koo
  • 33
  • 5

0 Answers0