0

I have a collection of 200 documents, when I'm using the "find" method I've got an error

MongoServerError: Cannot run getMore on cursor 5866951209337451201, which was created in session bcd516cd-227f-4df6-bc52-5aca331c08e9 - 47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=, without an lsid

But if I limit the number of returned documents to 100 it works fine.

rickhg12hs
  • 10,638
  • 6
  • 24
  • 42
Yevhen Kazmirchuk
  • 119
  • 1
  • 1
  • 6
  • 1
    how do you create this command? – dododo Jul 13 '22 at 00:04
  • @dododo seems like MongoDB doesn't allow you to get more than 100 documents using the same cursor by default, to change this, I need to change batchSize option – Yevhen Kazmirchuk Jul 13 '22 at 11:07
  • 1
    batchSize is always there, see https://stackoverflow.com/questions/52057720/default-batch-size-in-aggregate-command-in-mongodb. But it doesn't explain your error – dododo Jul 13 '22 at 12:13
  • @dododo As I understand if I need to map through the collection, I need to implement this by myself, like pagination? – Yevhen Kazmirchuk Jul 14 '22 at 11:22
  • 1
    you should use a default driver find cursor interface and configure skip: https://www.mongodb.com/docs/manual/reference/method/cursor.skip/ and batchSize https://www.mongodb.com/docs/manual/reference/method/cursor.batchSize/#mongodb-method-cursor.batchSize options – dododo Jul 14 '22 at 11:46
  • @dododo I've found why it fails. It happened inside of the cron job, cause I forgot to establish a connection with the database – Yevhen Kazmirchuk Aug 08 '22 at 09:29

0 Answers0