1

So after building a chat app with angularjs and PHP I realized it was horrible for server performance and decided to give firebase a try using angularjs to talk with firebase(angularfire) right now I have hit a little roadblock and can't seem to figure out how to accomplish displaying a users chat rooms he's apart of. Please note this is my FIRST time using NoSql structure.

Currently my structure is like so:

{
  "-K4KXS4k3mftFMe7jy_g" : {
    "members" : {
      "guest:Aaaa1aa" : {
        "user1" : "Aaaa1aa",
        "user2" : "guest"
      }
    },
    "messages" : {
      "guest:Aaaa1aa" : {
        "-K4LdBwkMe7dcshqCXxW" : {
          "content" : "gg",
          "from" : "Aaaa1aa"
        }
      }
    },
    "rooms" : {
      "guest:Aaaa1aa" : {
        "roomname" : "guestAaaa1aa",
        "type" : "private"
      }
    }
  }
}

I want to check if

members->'key'->user1 == 'Aaaa1aa'

but the way I construct the key for each members data(from room key) is passed two parameters when the user clicks on 'message'(creates new room or opens existing room) in another function and that is their user name and the users profile name they clicked on. hence the keys with the delimiter ':' (guest:Aaaa1aa).

So my question is can I check if the members key contains a substring value ? sort of like explode in PHP.

What I want my query to be like:

select uniqueid(room_name) from members where user1 = 'passed value'

and if above is possible would the below be possible as well ?

select uniqueid(room_name) from members where user1 = 'passed value' || user2 = 'passed value'

thanks for any help, if I am structuring this wrong please let me know and point me into the right direction.

Community
  • 1
  • 1
Spade
  • 591
  • 3
  • 20
  • Firebase does not support a "contains" operator in its queries. See http://stackoverflow.com/questions/28589092/firebase-query-find-item-with-child-that-contains-string If you're new to NoSQL, I *highly* recommend reading this [article about NoSQL data modeling](https://highlyscalable.wordpress.com/2012/03/01/nosql-data-modeling-techniques/). – Frank van Puffelen Nov 30 '15 at 15:25
  • Thanks @FrankvanPuffelen I'll take a look at the article now! I did however manage to pull the messages into grouped rooms like I wanted by pulling all the member records, and then running over that array finding matching records, after finding them used those matching member record id names to pull each set of chat messages! – Spade Nov 30 '15 at 21:14

0 Answers0