Medvedev Medvedev - 4 months ago 31
Node.js Question

RethinkDB: get only one record from cursor

How to get only one record from cursor using secondary indexes?

r.db('domains').table('info').getAll(domain, {index: 'domain'}).run connection, (err, cursor) ->
throw err if err
cursor.toArray (err, info) ->
throw err if err
callback info

How to get only one record?


Probably the easiest way is to modify your query like so:

r.db('domains').table('info').getAll(domain, {index: 'domain'}).limit(1)

That will give you back only the first document. You could also only consume 1 document from the cursor. But that's probably not quite as clean.