简体   繁体   English

SQL中等效的Firebase连接,分组,聚合

[英]Firebase Joining, Grouping, Aggregation Equivalent in SQL

I am coming from SQL and trying Firebase for the fist time. 我来自SQL,第一时间尝试使用Firebase。 Is this query possible with Firebase? Firebase是否可以进行此查询?

SELECT
    name,
    AVG(rating) as avgRating
FROM restaurants
JOIN reviews
    ON restaurants.ID = reviews.restaurantsID
GROUP BY restaurants.ID
ORDER BY avgRating;

If yes, can you provide me a link to a blog, tutorial or an advanced course on Firebase for SQL guys? 如果是,您可以为我提供指向Firebase的博客,教程或高级课程的链接吗? (preferably Firebase for Web) (最好是Firebase for Web)

Joins are the primary weak point for all NoSQL style databases. 联接是所有NoSQL样式数据库的主要弱点。 This arises from the way they work: a query is just a straight read of a JSON store. 这源于它们的工作方式:查询只是对JSON存储的直接读取。 (Which also gives them their strength: speed and scalability.) (这也为他们提供了优势:速度和可伸缩性。)

If you are using Firebase real-time DB, then the best approach to this is to denormalize your data and perform two queries. 如果您使用的是Firebase实时数据库,那么最好的方法是对数据进行非规范化并执行两个查询。 That would look something like this: 看起来像这样:

firebase.db.ref("/path/to/ref").on("value", (snapshot) => {
  if(snapshot.val()){
    firebase.db.ref(`/second/ref/${snapshot.val().joinValue}`).on("value", (snapshot2) => {
      console.log(snapshot2.val()) // Do something
    }
  }
})

Recently, Firebase released their new FireStore database that is implemented to address some of the weak points with the real-time version. 最近,Firebase发布了他们的新FireStore数据库 ,该数据库旨在解决实时版本中的某些弱点。 However, I don't think the join problem is specifically addressed (the end solution is probably similar to my example.) 但是,我认为联接问题不是专门解决的(最终解决方案可能与我的示例类似。)

Finally, I work with Firebase quite a bit and I suspect they are probably working with a GraphQL inspired solution which would be a full interface for a SQL based DB. 最后,我与Firebase进行了大量合作,我怀疑他们可能正在使用GraphQL启发性的解决方案,该解决方案将成为基于SQL的数据库的完整接口。 I would expect that to drop in the next 12 months. 我希望该数字在未来12个月内会下降。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM