jeroen / mongolite

Fast and Simple MongoDB Client for R
https://jeroen.github.io/mongolite/
284 stars 64 forks source link

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

Open bfurtwa opened 5 years ago

bfurtwa commented 5 years ago

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

enricodata commented 5 years ago

did you solve this? I am having the same issue

ploner commented 4 years ago

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
)
pabecerra commented 2 years ago

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)
}