distinct
ReQL command: distinct
Command syntax
sequence.distinct() → array table.distinct([{index: <indexname>}]) → stream r.distinct(sequence) → array r.distinct(table, [{index: <indexname>}]) → stream
Description
Removes duplicates from elements in a sequence.
The distinct
command can be called on any sequence or table with an index.
While
distinct
can be called on a table without an index, the only effect will be to convert the table into a stream; the content of the stream will not be affected.
Example: Which unique villains have been vanquished by Marvel heroes?
r.table('marvel').concatMap(function(hero) { return hero('villainList') }).distinct().run(conn, callback)
Example: Topics in a table of messages have a secondary index on them, and more than one message can have the same topic. What are the unique topics in the table?
r.table('messages').distinct({index: 'topics'}).run(conn, callback)
The above structure is functionally identical to:
r.table('messages')('topics').distinct().run(conn, callback)
However, the first form (passing the index as an argument to distinct
) is faster, and won’t run into array limit issues since it’s returning a stream.
Related commands
Get more help
Couldn't find what you were looking for?
- Ask a question on Stack Overflow
- Chat with us and our community on Slack
- Talk to the team on IRC on #rethinkdb@freenode.net — via Webchat
- Ping @rethinkdb on Twitter
- Post an issue on the documentation issue tracker on GitHub
© RethinkDB contributors
Licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License.
https://rethinkdb.com/api/javascript/distinct/