Firebase Equivalent To NOT IN array


#1

Hi.
I am very new to both Firebase and Ionic and I am really confused. Is there a way we can exclude those blocked items in the results using Firebase like NOT IN array? The blocked items that I am talking about are the items that are saved in another table.

Below is a very basic structure :

*posts
    -post_id
    -title
    -desc
    -timestamp
    -other_data
*user
    -user_id
    -name
    -other_data
*blocked_posts
    -how should I implement this

Thanks in advance…


#2

you can get the key of the specific post, add it to *blocked_posts and assign it a value of true. Then, you can check to see if each post is in the blocked_posts table with

let checkTheseKeys = firebase.database().ref('posts');
let blockedKeys = firebase.database().ref('blocked_posts');

  checkTheseKeys.on("child_added", (snapshot) => {
     let checkThisKey = snapshot.key;
     let blockedCheck = blockedKeys.child(checkThisKey);
         
     blockedCheck.once("value", (snapshot) => {
         let doesExist = snapshot.exists();
         if (doesExist === true)  {
             //it's in blocked posts
             console.log('its blocked');
             }  else {
              //equivalent to not in array
               console.log("it's not in blocked posts")  
            }
       }
}

When doing something like this with Firebase, you’re not actually checking the value of the key you’re looking for, you’re just checking to see if the key exists.

I am by no means an expert on using firebase, but this type of action has worked for me in the past.