0

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!

Vafilor
  • 75
  • 1
  • 1
  • 9
  • 1
    Firestore currently does not support queries on inequality, i.e. you can't query for items that *don't* have a certain field/value. See https://stackoverflow.com/questions/47251919/firestore-how-to-perform-a-query-with-inequality-not-equals, https://stackoverflow.com/questions/47195122/firestore-comparison-operators-contains-does-not-contain-starts-with – Frank van Puffelen May 26 '18 at 04:14
  • @FrankvanPuffelen Thanks for the links! I was hoping to find a way to structure my data differently to achieve the same effect, but haven't found anything - apart from local filtering of data. Seems like firebase isn't the way to go to implement what I need. – Vafilor May 29 '18 at 15:13

0 Answers0