PHP MongoDB - Use of the aggregate command without the cursor option is deprecated. What?

前端 未结 6 731
醉话见心
醉话见心 2020-12-16 20:32

I have updated mongo and now in the log the following error appears: Use of the aggregate command without the cursor option is deprecated

Mo

6条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-16 21:01

    When you query something to MongoDB and you expect results, you will have this variable called cursor, which simply is a pointer to the document you currently did read. It is just like a scrollbar in the browser.

    You can specify how many documents it should read into a buffer batchSize as you did with value 1.

    It is useful when you know how much documents you expect to read. When you only need 10 documents, you can get all those in a single network packet using batchSize => 10. When specify batchSize => 5, it will take longer because it does take two network packets to the database to get the expected 10 documents.

    You are safe using the default batchSize.

    You can try to iterate over the cursor using foreach like in an example in the docs: http://php.net/manual/en/class.mongocommandcursor.php

    Im not sure if the php.net documentation is up to date with the most current version of the MongoDB driver.

提交回复
热议问题