Use cursor for counting documents