javascript - Firebase, query "not equal to" - Stack Overflow

Here my database structure :{"feeling" : {"fake0" : {"fake1" : {...},&quo

Here my database structure :

{
  "feeling" : {
    "fake0" : {
      "fake1" : {...},
      "fake2" : {...}
    }
  },
  "profile" : {
    "fake0" : {...},
    "fake1" : {...},
    "fake2" : {...},
    "fake3" : {...}
  }
}

If the logged user is "fake0", how can he fetch all profiles that are not in his feeling ?

I would like to do something like : ref("/profile", {notEqualTo: ["fake1","fake2"]}).on('once', .....)

Perhaps my structure is bad, just tell me a better one and I will change it :) !

Here my database structure :

{
  "feeling" : {
    "fake0" : {
      "fake1" : {...},
      "fake2" : {...}
    }
  },
  "profile" : {
    "fake0" : {...},
    "fake1" : {...},
    "fake2" : {...},
    "fake3" : {...}
  }
}

If the logged user is "fake0", how can he fetch all profiles that are not in his feeling ?

I would like to do something like : ref("/profile", {notEqualTo: ["fake1","fake2"]}).on('once', .....)

Perhaps my structure is bad, just tell me a better one and I will change it :) !

Share Improve this question edited Aug 17, 2017 at 16:59 Charly berthet asked Aug 17, 2017 at 15:57 Charly berthetCharly berthet 1,3165 gold badges17 silver badges33 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

This and a few other similar questions (Firebase: Query to exclude data based on a condition) and my experience with Firebase leads me to believe that there aren't any functionalities in Firebase that do this directly.

Now you can filter by property, which isn't entirely what you're looking for, but it might be useful for you to structure your database so that user profiles also contain reference to the /users who contain them/ in their feeling. Thus, your query would get much easier. You probably also want to, as mentioned in the other StackOverflow thread linked above, use the user ID as the key and store its value as "true." This way you can check by ID, which if I recall correctly is easier than checking value.

I know Firebase also remends that you store a little bit of redundant information; it's a matter of whether you want to put in the effort when writing or reading.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743730655a4497376.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信