Method: WeaviateRecord::Base.count
- Defined in:
- lib/weaviate_record/base.rb
.count ⇒ Object
Returns the count of all records in the collection.
Example:
class Article < WeaviateRecord::Base
end
Article.count # => 0
Article.create(title: 'Hello World', content: 'This is the content of the article')
Article.count # => 1
63 64 65 66 67 68 |
# File 'lib/weaviate_record/base.rb', line 63 def count result = connection.client.query.aggs(class_name: to_s, fields: 'meta { count }') result.dig(0, 'meta', 'count') rescue StandardError raise WeaviateRecord::Errors::ServerError, "unable to get the count for #{self} collection." end |