I'm developing an application in Firebase for the first time and am trying to figure out the best way to store a relationship like Users and Stocks.
Users can watch specific stocks, and stock prices can change.
Something like this
User {
firstName: "Joe",
lastName: "Smith"
}
Stock {
name: "GOOGL",
currentPrice: 108408 //In cents
}
I want to be able to do queries like
- Get all stocks watched by Joe
- Get all stocks NOT watched by Joe (in case he wants to add some he hasn't seen)
I started out with a Stock collection, but am having difficulty doing the above queries.
Tried something like this
Stock {
//previous fields
watchedBy: {
"joeUserId": true
}
}
Which allows finding stocks Joe is watching, but not stocks Joe is NOT watching? Also, I read there's a limit of 1MB per document, so what if I have millions of users? This can't store all of it?
Thanks!