RethinkDB: using concatMap to get distinct field values

By John Keyes

May 3, 2024 at 16:36

rethinkdb

Using concatMap to get distinct field values

The Journey table records all journeys in the system. Each record has a userId field to represent the user who went on that journey. How can we find out how many users went on journeys?

Using concatMap we transform this sequence of documents into a sequence of userId strings. When we have this sequence we can remove duplicates by calling the distinct operation:

For example:

  r.db("faceitdown")
    .table("Journey")
    .filter(...)
    .concatMap(function(journey) {
     return [journey('userId')]
    }) // after applying this function the result is an array of strings
    .distinct()
    .count()

Last updated: May 3, 2024 at 16:36