0

How am I able to fetch only elements with specified key?

In my case I have n of entries by users. If the entry is new - it's unverified and I dont want it to be fetched by other users (I dont want it to display on users screen).

So until the entry is verified, it has to be invisible.

Let's say that each entry contains a flag isVerified which is false by default. After verification it changes to true.

How to tell firebase to fetch only these entries with true as value of isVerified key?

Tried queries, but failed. It should be something like ref.orderByChild('isVerified').isTruthy or so?

1 Answer 1

3

You can use equalTo() to retrieve values with child property isVerified equal to true. This would need to be done in combination with and ordering function such as orderByChild()

let ref = firebase.database().ref("foobar");
ref.orderByChild("isVerified").equalTo(true).once("value", function(snapshot) {
  /// ... do something with snapshot
});

Firebase has helpful documentation/examples regarding sorting and filtering data.

Hopefully that helps!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.