如何在firebase中查询反应? [英] How to query in firebase in react?

查看:49
本文介绍了如何在firebase中查询反应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在firebase中具有以下数据结构

I have the following data structure in firebase

{
 "users":{
"Arshak Anjum": {
    "UserName": "Arshak Anjum",
    "admin": 0,
    "status": 0,
    "UserId": 959125570900519
 } 
 }
 }

仅当该人的状态为0时,我才想查询数据库并加载页面.
如何设置对用户的引用并按名称查询.
我想查询从id ="Arshak Anjum"和status = 1的用户中选择*;"
我正在使用react

I want to query the database and load the page only if the status of that person is 0.
How do I set up a reference to users and query by name.
I want to query "Select * from users where id="Arshak Anjum" AND status=1;"
I am using react

var userRef = database.ref('/users/'+authData.displayName);
var user=userRef.where("status","==",1)

此代码无效.我是Firebase的初学者.另外,在执行某些操作后,如何将状态更新为1.

This code doesn't work. I am a beginner in firebase. Also how do i update the status to 1 after some operations.

推荐答案

您显示的代码显示了Cloud Firestore的查询语法,该语法与Firebase Realtime数据库不兼容.要查询后者,请使用其文档.例如:

The code you have show the query syntax for Cloud Firestore, which is not compatible with the Firebase Realtime Database. To query the latter, use the methods mentioned in its documentation. For example:

var userRef = database.ref('/users/'+authData.displayName);
var userQuery = userRef.orderByChild("status").equalTo(1);
userQuery.once("value", function(snapshot) {
  snapshot.forEach(function(child) {
    console.log(child.key, child.val());
  });
});

这篇关于如何在firebase中查询反应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆