Medvedev Medvedev - 1 year ago 92
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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download