实时数据库Firebase中的多查询?

时间:2020-09-08 04:43:53

标签: javascript firebase-realtime-database multi-query

我有一个这样的结构json

"posts" : {
    "pid01" : {
      "byUser" : "uid01",
      "content" : "Trói em bằng cà vạt, penhouse trên đà lạt. Nếu mà ngoan em sẽ bị thương, nếu mà hư em sẽ được phạt",
      "featureImg" : "",
      "inCat" : "cid02",
      "postViews" : 30,
      "postedDate" : 1597914650586,
      "title" : "BigCityBoi"
    },
    "pid02" : {
      "byUser" : "uid01",
      "content" : "Đây là một bộ manga do mình tự nghĩ chơi, chả có cái huần hèo gì đặc biệt hết á",
      "featureImg" : "",
      "inCat" : "cid03",
      "postViews" : 32,
      "postedDate" : 1597915982705,
      "title" : "Tôn Ngộ Không Chân Hoàn truyện"
    },
    "pid03" : {
      "byUser" : "uid01",
      "content" : "Thanh niên này là 1 rapper chính hiệu nổi lên từ giới underground",
      "featureImg" : "",
      "inCat" : "cid02",
      "postViews" : 40,
      "postedDate" : 1597646378746,
      "title" : "Wowy là ai"
    },
    "pid04" : {
      "byUser" : "uid01",
      "content" : "Test cho slider",
      "featureImg" : "",
      "inCat" : "cid02",
      "postViews" : 44,
      "postedDate" : 1597915885508,
      "title" : "Hello"
    }
  }

如何查询2种条件:inCat = value并获得前2个postView ??

我正在按以下方式使用,但无法正常工作。我想显示每个类别的所有帖子,并使用条件顶部2个帖子视图对其进行查询(当用户查看时,帖子视图会自动增加1):

const postRef = rootDbRef.child("posts").orderByChild('inCat').equalTo(cat.id).orderByChild('postViews').limitToLast(2)
``

0 个答案:

没有答案