PHP MongoDB - 不建议使用不带游标选项的聚合命令。什么? [英] PHP MongoDB - Use of the aggregate command without the cursor option is deprecated. What?

查看:119
本文介绍了PHP MongoDB - 不建议使用不带游标选项的聚合命令。什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我更新了mongo,现在在日志中出现以下错误:
不使用游标选项使用聚合命令已被弃用



Mongo说我应该为聚合函数放置第二个REQUIRED参数,因为我目前的用法已被废弃。



我目前使用下面的代码PHP(现已弃用):

  $ this-> db-> {$ collection}  - >骨料($选项); 

并返回此格式:

<$ p $ {result:[
{
_id:xxxxxx,
update:[
{
firstUpdateTime:xxxxxx,
updateTime:xxxxxxx,
}
],
media:[
{
xxxx:{。 ..

为了不使用已弃用的代码,我添加了新的第二个参数不明白要放什么):

  $ this-> db-> {$ collection}  - > ; aggregate($ options,array('cursor'=> array('batchSize'=> 101))); 

这将返回相同的信息,但会改变初始结构:

  {cursor:{
id:{
value:xxxxxx
},
ns:xxxxxx.instagram,
firstBatch:[
{
_id:xxxxxx,
update:[
{
firstUpdateTime:xxxxxx,
updateTime:xxxxxx,
}
],
media:[
{
xxxxxx:{...

更新后,Mongo迫使我改变阅读方式数据。
我不明白我应该在第二个参数cursor中加入什么值... ...

我应该在第二个参数参数?
我可以在不更改结果结构的情况下设置默认值吗?
$ b 文档:
https://docs.mongodb.com/manual/reference/method/db.collection.aggregate/
http://php.net/manual/es/mongocollection .aggregate.php


更新:

函数I中的光标不再收到错误。
但是,如果没有应用到解决方案中,我会阅读LOG,随机出现警告,我有一段代码,我会多次运行,有时会报告上述警告,而有些则不会。



为什么?

解决方案

当您向MongoDB查询某些内容并期望得到结果时,这个变量叫做 cursor ,它只是一个指向你当前读过的文档的指针。它就像浏览器中的滚动条。



您可以指定它应该读入缓冲区的文件数量 batchSize 就像你的值 1



当你知道你期望阅读多少文档时,这很有用。当您只需要10个文档时,您可以使用 batchSize =>来获取单个网络数据包中的所有文档。 10 。当指定 batchSize => 5 ,它会花费更长时间,因为它确实需要两个网络数据包才能获得预期的10个文档。



您可以安全地使用默认 batchSize



你可以尝试使用 foreach 喜欢在文档中的示例: http://php.net/ manual / en / class.mongocommandcursor.php



我不确定php.net文档是否与最新版本的MongoDB驱动程序保持同步。


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

Mongo says that I should put a second REQUIRED parameter to aggregate function, because my current usage is deprecated.

I currently use the following code PHP (now is deprecated):

$this->db->{$collection}->aggregate($options);

And return this format:

{"result":[
    {
    "_id":"xxxxxx",
    "update":[
    {
    "firstUpdateTime":xxxxxx,
    "updateTime":xxxxxxx,
    }
    ],
    "media":[
    {
    "xxxx":{ ...

To not use an deprecated code I add the new second parameter (but I do not understand what to put):

$this->db->{$collection}->aggregate($options, array('cursor' => array('batchSize' => 101)));

And this returns the same information but varies the initial structure:

{"cursor":{
"id":{
"value":"xxxxxx"
},
"ns":"xxxxxx.instagram",
"firstBatch":[
{
"_id":"xxxxxx",
"update":[
{
"firstUpdateTime":xxxxxx,
"updateTime":xxxxxx,
}
],
"media":[
{
"xxxxxx":{ ...

After the update Mongo forces me to change the way I read the data. I don't understand what value I should put in that second parameter called "cursor"...

What should I put in that second parameter? Can I set a default value without altering the structure of results?

Doc: https://docs.mongodb.com/manual/reference/method/db.collection.aggregate/ http://php.net/manual/es/mongocollection.aggregate.php

UPDATE:

If I indicate the cursor in the function I no longer receive the error. But without applying to the solution, I read the LOG and the warning appears at random, I have a code that I run several times and sometimes if it reports the mentioned warning and others do not.

Why?

解决方案

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.

这篇关于PHP MongoDB - 不建议使用不带游标选项的聚合命令。什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆