I have a dataset of records stored in a database and I've been attempting to extract a complex set of information from these records.
Here are some sample records for reference:
{
bookId : '135wfkjdbv',
type : 'a',
store : 'barnes & noble',
shelf : 'A1'
}
{
bookId : '13erjfn',
type : 'b',
store : 'barnes & noble',
shelf : 'A2'
}
I'm looking to extract data that will provide, for each unique bookId, the count of records per shelf for each store where the book belongs to type 'a'.
Although I am aware that an aggregation query allows for various operations such as grouping and matching, I have not yet found a solution to this particular problem.
The desired output should look like this:
{
bookId : '135wfkjdbv',
stores : [
{
name : 'barnes & noble',
shelves : [
{
name : 'A1',
count : 12
},
]
},
{
name : 'books-a-million',
shelves : [
{
name : 'B3',
count : 8
},
{
name : 'D5',
count : 15
},
]
}
]
}