Matias Celiz
Matias Celiz

Reputation: 322

Firebase query into nodes

A question, how I can do this queries?

Schema

-|conversations
-|$uid
    -|fromID
        -|message
            name: string
            date: date
            body: string
            like: boolea

If the user is the transmitter of the message, the followers are all collections into conversations/$uid and the followed users are in conversations/ANYTHING/$uid.

I can list the followers for this way this.followers = this.af.database.list(conversations/${this.currentAuth.uid});

But, and the followed users?

Add this diagram to a better explain enter image description here

Upvotes: 1

Views: 86

Answers (2)

Matias Celiz
Matias Celiz

Reputation: 322

The solution was add two nodes. followers and followed into each profile to save all keys.

Upvotes: 0

Wandrille
Wandrille

Reputation: 6811

So, with database.list, you get an array of messages.

For each message in the list, you have meta data which are added.

you can get the key of your message (so the followed user ID) with the key: "$key"

example:

const message = this.af.database.list(conversations/${this.currentAuth.uid});

message[0].$key will give you the user_id of the followed user.

EDIT 1:

I don't really understand what you are trying to do. But what you suggest in the comment will be:

If you use Lodash:

this will give you all the conversations with this.currentAuth.uid as fromID:

_.filter(
    this.af.database.list(conversations),
    function (o) => { 
        return Object.keys(o).indexOf(this.currentAuth.uid) != -1 
    }

)

Upvotes: 1

Related Questions