I have been searching for a solution for the past 2 hours, but unfortunately haven't found one yet. Although I have experience working with both SQL and NoSQL databases, this particular issue is new to me. My problem is quite straightforward: I have two collections - Raw Materials and Raw Materials Stock. Each document in the Raw Materials Stock collection includes a key for the raw material. What I need to do is retrieve the data of the raw material based on its key and join it with the list of raw material stocks. For example: The Raw Materials Stock document looks like this
{
"factoryKey": "34",
"quantity": "34",
// I want to fetch details such as name for this raw material key
"rawMaterialKey": "-NDNPe47CDTbjmwGgW_3"
}
The Raw Material document looks like this
{
"key": "-NDNPe47CDTbjmwGgW_3",
"code": "R34",
"name": "RAW2001"
}
Here's my Angular code:
import {Injectable, OnInit} from '@angular/core';
import {LocalStoreService} from '../local-store.service';
import {AngularFirestore} from '@angular/fire/compat/firestore';
import {Router} from '@angular/router';
import { RawMaterialStock } from '../../interfaces/raw-materials/raw-materiels-stock';
import {AngularFireDatabase, AngularFireList, AngularFireObject } from '@angular/fire/compat/database';
@Injectable({
providedIn: 'root',
})
export class RawMaterialsStockService implements OnInit {
rawMaterialsStocksRef: AngularFireList<any>;
rawMaterialsRef: AngularFireList<any>;
rawMaterialStockRef: AngularFireObject<any>;
private dbPathStock = '/raw_material_stock';
private dbPathRawMaterials = '/raw_material';
constructor(
private store: LocalStoreService,
private router: Router,
private afs: AngularFirestore,
private db: AngularFireDatabase
) {
this.rawMaterialsStocksRef = db.list(this.dbPathStock);
this.rawMaterialsRef = db.list(this.dbPathRawMaterials);
}
ngOnInit(): void {
}
// Methods
getRawMaterialStockList() {
return this.rawMaterialsStocksRef.snapshotChanges(['child_added'])
.subscribe(actions => {
// WHAT SHOULD I DO HERE ????
});
}
}
I'd greatly appreciate any help with this problem. I seem to be stuck and unable to find any resources that address this specific issue!