1
votes

TASK: Get random friend suggestions from User collection.

This is a User collection example:

{
  "firstname": "John",
  "lastname": "Doe",
  "username": "johndoe",
  "email": "[email protected]"
}

I also have an edge collection friendRequest that stores friend requests like this:

_from: "User/John" -> _to: "User/Jane"

PROBLEM: I want to filter out my self and Users I already sent a request to.

This is my initial query to get 3 users excluding myself

FOR user IN User
FILTER user._key != 'myself'
SORT RAND()
LIMIT 3
RETURN user

I want to be able to exclude people I've already sent a request to using something like FILTER NOT IN (<<SOME EDGE QUERY>>)

NOTE: I also have a graph friendRequest_graph that relates friendRequest edge between User collections

1

1 Answers

1
votes

I found out that I can do that with this query!

FOR user IN User
  FILTER user._key != 'myself' && 
  user._key NOT IN (FOR fr IN friendRequest FILTER fr._from == 'User/myself' RETURN LTRIM(fr._to, 'User/'))
  SORT RAND()
  LIMIT 3
  RETURN user