Charly berthet
Charly berthet

Reputation: 1296

Firebase, query "not equal to"

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 :) !

Upvotes: 6

Views: 16025

Answers (1)

Giselle Serate
Giselle Serate

Reputation: 184

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 recommends 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.

Upvotes: 8

Related Questions