从mongo读取370k文档时找不到光标

时间:2019-01-07 13:10:52

标签: mongodb reactivemongo

我有一个简单的方法,它从mongo的人员集合中读取数据流,并为每个人进行一些模型更改并插入到新的集中:

  def processPeople()(implicit m: Materializer): Future[Done] = {
    val peopleSource: Source[Person, Future[State]] = collection.find(json())
      .cursor[Person]()
      .documentSource()
      .throttle(50, 1.second)

    peopleSource.runForeach(person => insertPerson(person))
  }

  def insertPerson(person: Person): Future[String] = {
    peopleCollection.insert(person) map { _ =>
      person.id
    } recover {
      case WriteResult.Code(11000) =>
        println(WriteResult.lastError(_))
        logger.error(s"fail to insert duplicate person ${person.id}")
        throw DuplicateInsertion("duplicate person")
      case _ =>
        logger.error(s"fail to insert person ${person.id}")
        throw new RuntimeException
    }
  }

该收藏集大约有370K文档,由于某种原因我得到了200k之后:

reactivemongo.core.errors.DetailedDatabaseException: DatabaseException['Cursor not found, cursor id: 72642197351' (code = 43)]

在mongo控制台中,我看到了:

I COMMAND  [conn45] killcursors: found 0 of 1

有人知道为什么会这样吗?

0 个答案:

没有答案