It looks like MongoDB doesn't support Stored Procedures, which would have been my first suggestion.
As an alternative, you can call getRecords() with include_count=true and offset=1000000000 or some other very large number (compared to your expected table size). It's very hacky, so hopefully someone can come up with a better solution.