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