rethinkdb check if record exists

浪尽此生 提交于 2019-12-13 08:43:30

问题


Here is an example:

r.db('my_db').table('my_table').get('my_record_id_123')

The above code works fine, but returns the record. The records in this table are huge. Is there a way to check if the record with that specific id exists or not without returning the record itself?


回答1:


Perhaps this is what you want (it will return true if the record exists or false otherwise):

r.db('my_db')
  .table('my_table')
  .getAll('my_record_id_123')
  .count()
  .eq(1)



回答2:


returns number

r.db('my_db')
  .table('my_table')
  .count(function(user){
    return user('id').eq(1121)
  })



回答3:


r.db('my_db')
  .table('my_table')
  .getAll('my_record_id_123')
  .contains()

This works for me :)



来源:https://stackoverflow.com/questions/43782915/rethinkdb-check-if-record-exists

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!