AJcodez
AJcodez

Reputation: 34166

How can i find out size of RethinkDB table?

I can't figure out how to get the data size of 'test.events' table.

r.db('rethinkdb').table('stats').whatGoesHere()
// Output size of 'events' table

Related: Get size of Rethinkdb database with Python

Upvotes: 6

Views: 2261

Answers (3)

Khalil Gharbaoui
Khalil Gharbaoui

Reputation: 7042

To list table sizes in MB:

r.db('rethinkdb').table('stats')
  .hasFields('db', 'table')
  .group('db', 'table')
  .map(doc => doc('storage_engine')('disk')('space_usage')('data_bytes').default(0))
  .sum()
  .ungroup()
  .map(doc => ({db: doc('group').nth(0), table: doc('group').nth(1), size: doc('reduction').div(1024).div(1024).round().coerceTo('string').add('MB')}))

To show the total of all tables in GB:

r.db('rethinkdb').table('stats')
  .hasFields('db', 'table')
  .group('db', 'table')
  .map(doc => doc('storage_engine')('disk')('space_usage')('data_bytes').default(0))
  .sum()
  .ungroup()
  .map(doc => ({db: doc('group').nth(0), table: doc('group').nth(1), size: doc('reduction').div(1024).div(1024)}))
  .sum('size')
  .div(1024)
  .round()
  .coerceTo('string')
  .add('GB')
     

Upvotes: 0

analytik
analytik

Reputation: 802

This will list space allocated on HDD across all nodes in RethinkDB cluster:

r.db("rethinkdb")
  .table("stats")
  .filter({db:'test', table:'events'})
  .map(doc => doc('storage_engine')('disk')('space_usage')('data_bytes').default(0))
  .sum()

Alternatively, to list table sizes in MB:

r.db("rethinkdb").table("stats")
  .hasFields('db', 'table')
  .group('db', 'table')
  .map(doc => doc('storage_engine')('disk')('space_usage')('data_bytes').default(0))
  .sum()
  .ungroup()
  .map(doc => ({db: doc('group').nth(0), table: doc('group').nth(1), size: doc('reduction').div(1024).div(1024)}));

Upvotes: 9

mlucy
mlucy

Reputation: 5289

You can call .count() to do that.

Upvotes: 0

Related Questions