Complex migration functions of MongoDB 3.2 to 3.4 in PHP

I created an application using MongoDB 3.2. I am trying to port it to MongoDB 3.4, as it includes some very necessary functions. Most of the migration went smoothly, with the exception of one - aggregate functions. My current aggregated functions are as follows:

$collection = $mongo->getCollection('users'); $results = $collection->aggregate(array( array('$match' => array('_id' => $_SESSION['user'])), array('$project' => array('viewed_cases' => 1)), array('$unwind' => '$viewed_cases'), )); 

However, this causes these problems in mongod:

Using an aggregate command without the cursor option is deprecated. See http://dochub.mongodb.org/core/aggregate-without-cursor-deprecation .

After reading the documentation, I tried to change the function to this by adding a cursor with batchSize set to the default value (an attempt to add only a cursor with an empty array, as suggested in the documentation, caused PHP to fail):

 $collection = $mongo->getCollection('users'); $results = $collection->aggregate(array( array('$match' => array('_id' => $_SESSION['user'])), array('$project' => array('viewed_cases' => 1)), array('$unwind' => '$viewed_cases'), ), array('cursor' => array('batchSize' => 101))); 

However, this changes the response sent to $ results. Instead of an array, it looks like this:

 array(2) { ["result"]=> array(4) { [0]=> array(2) { ["_id"]=> string(4) "idan" ["viewed_cases"]=> array(2) { ... } } } } 

which I accessed through $ results ['result'], now I get the following:

 array(2) { ["cursor"]=> array(3) { ["id"]=> object(MongoInt64)#10 (1) { ["value"]=> string(1) "0" } ["ns"]=> string(10) "work.users" ["firstBatch"]=> array(4) { [0]=> array(2) { ["_id"]=> string(4) "idan" ["viewed_cases"]=> array(2) { ... } } } } } 

With this implementation, with the exception of the fact that it requires changing all calls to $, it leads to the whole system, I am worried about unforeseen results in the future, given that everything is under "firstBatch". I assume that I will need to create support for the following parties, which is currently not the case.

Is there a way to change the original 3.2-support aggregate function above to be compatible with 3.4 without changing the response sent to $ results?

Thanks in advance

0
php mongodb
source share

No one has answered this question yet.

See similar questions:

nine
PHP MongoDB - Using an aggregate command without a cursor option is deprecated. What kind?

or similar:

2414
Why shouldn't I use mysql_ * functions in PHP?
1387
startsWith () and endsWith () functions in PHP
1065
Link. What does this error mean in PHP?
241
Ways to implement data versioning in MongoDB
2
Using aggregate in MongoDB 3.2 with $ lookup to match based on an array of values
one
PHP MongoDB driver error while updatingOne
one
MongoDB aggregation request with shutdown without savingNullAndEmptyArrays
one
Aggregation with MongoDB 3.6 and Morphia 1.3.2
one
Mongodb 3.2 and $ 3.0 unwind aggregation
0
C # MongoDB Driver Aggregation Structure with Update

All Articles