Firebase 数据库查询列表不等于 [英] Firebase Database query list for not equal to

查看:32
本文介绍了Firebase 数据库查询列表不等于的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 AngularFire2 的 Angular 4 应用中使用 Firebase.我的数据库结构是这样的.

I am using Firebase in my Angular 4 app using AngularFire2. I have my database structure something like this.

{
  "users": {
    "-Kr6HDbj9tMxmxsQ8UnM": {
      "name": "abc",
      "email": "xyz@example.com",
      "uid": "XLTPwGtFYcX6xVHbJGerHxGayT2"
    },
    "-Kr6JBzN_9PZAMctYwt-": {
      "name": "pqr",
      "email": "pqr@example.com"
      "uid": "cdIj8YOncYYiUIEJrb65ynfFcl2"
    },
    ............
  }
}

我想检索此数据结构的最后两个条目,但排除 uid 不等于 auth.uid 的数据.

I want to retrieve the last two entries of this data structure but exclude the data where uid is not equal to auth.uid.

推荐答案

我认为如果你改变数据结构会更容易,这样每个用户的键就是他们的 uid,就像这样.

I think it would be easier if you changed the datastructure so the key of each user is their uid, like this.

{
"users": {
    "XLTPwGtFYcX6xVHbJGerHxGayT2": {
      "...": ".........",
      "...": "........."
    },
    "cdIj8YOncYYiUIEJrb65ynfFcl2": {
      "...": ".........",
      "...": "........."
    }
}

然后您就可以轻松访问特定用户的属性使用 https://firebase.google.com/docs/参考/js/firebase.database.Reference#once

Then you could easily access the specific users properties With the https://firebase.google.com/docs/reference/js/firebase.database.Reference#once

示例

var ref = firebase.database().ref("users/"+auth.uid);
ref.once('value')
    .then(function(dataSnapshot) {
    // handle read data.
});

这篇关于Firebase 数据库查询列表不等于的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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