A<->B many to many, query for all As with no Bs


I’ve struggled with this for too long now. I haven’t been able to piece together the documentation for querying a many-to-many relationship for the records of one collection that have no relations through the “joins” collection.

I have songs, tags, and song_tags. I want to get all the songs that haven’t been tagged.


I think what I want to do is query for all the songs with an index, and then do a Difference of that and all the song ids present in the all_song_tags index. I’m still struggling to find the right FQL syntax for that mapping.

I’m also using the @relation resolver in GraphQL, if that makes a difference.


I think I figured it out.

I made a new index called allSongTagSongs.

  name: "allSongTagSongs",
  unique: true,
  serialized: true,
  source: "song_tags",
  values: [
      field: ["data", "songID"]

Then took the Difference from the allSongs index.


Using Distinct because it’s many-to-many so there are duplicate song refs in the index.

1 Like