问题
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