I'm new with Firestore and I'm trying to migrate a MongoDB project to Firestore. I have the following issue. My data structure is this one:
/products
'A': {name: 'Product A', price: 1},
'B': {name: 'Product B', price: 2}
/profiles
'1': {name: 'John', purchases: [ {product: 'A', quantity: 1} ] }
I have a collection of products and a collection of profiles. These profiles have an array of purchases, and each purchase has a object reference to the corresponding product and a quantity. With MongoDb I could do this:
const profiles = await Profiles.findById('1').populate('purchases.product', 'name price');
So I could get the following object:
{
_id: '1',
name: 'John',
purchases: [
{
{
_id: 'A',
name: 'Product A',
price: 1,
},
quantity: 1,
}
]
}
So with one query I can get all the purchases, I don't have to iterate through all purchases and get them by id. How can I achieve the same performance with Firestore? Also if this data model doesn't work as well with Firestore please tell me.