mongolite icon indicating copy to clipboard operation
mongolite copied to clipboard

collection$iterate()$batch(n=10000) returns "Error: Cannot advance a completed or failed cursor." instead of NULL when exhausted

Open bfurtwa opened this issue 7 years ago • 3 comments

I think when the iterator is exhausted it should return NULL.

bfurtwa avatar Dec 11 '18 17:12 bfurtwa

did you solve this? I am having the same issue

enricodata avatar Mar 21 '19 15:03 enricodata

I had the same issue. Solved it simply using:

it = collection$iterate(query) 
res = c() 
try(
  repeat({
    res = dplyr::bind_rows(res, it$page(size=10000))
  }),
  silent=TRUE
)

ploner avatar Oct 15 '19 12:10 ploner

Me too have this issue. This is my solution:

it = con$iterate("{}")
out <- NULL

while(!is.null(tryCatch(x <- it$page(size=10000), 
                        error = function(e){x <<-  NULL}))){
  #Do something
  out <- dplyr::bind_rows(out, x)
}

pabecerra avatar Nov 26 '21 14:11 pabecerra