Skip to content

Commit

Permalink
Merge pull request #1956 from jmikola/builder-cleanup
Browse files Browse the repository at this point in the history
Remove previously deprecated operations from Query Builder
  • Loading branch information
alcaeus committed Apr 12, 2019
2 parents 9574ed8 + 62eed4d commit 280e05e
Show file tree
Hide file tree
Showing 8 changed files with 6 additions and 460 deletions.
4 changes: 4 additions & 0 deletions UPGRADE-2.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,10 @@ ocramius. If you are checking for proxies, the following changed:
* Running `geoNear` commands through the `geoNear` helper in the query builder
is no longer supported. Please refactor your queries to use the aggregation
framework and `$geoNear` pipeline operator.
* Running `group` and `mapReduce` commands through the query builder is no
longer supported. Please either refactor your queries to use the aggregation
framework or use the MongoDB library (`mongodb/mongodb`) to execute these
commands.
* The `Doctrine\ODM\MongoDB\Query\FieldExtractor` class was dropped entirely.
* The `getIterator` method in `Doctrine\ODM\MongoDB\Query\Query` returns an
iterator of type `Doctrine\ODM\MongoDB\Iterator\Iterator` instead of a MongoDB
Expand Down
119 changes: 0 additions & 119 deletions docs/en/reference/map-reduce.rst

This file was deleted.

78 changes: 0 additions & 78 deletions docs/en/reference/query-builder-api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ The ``Query`` object supports several types of queries
- INSERT
- UPDATE
- REMOVE
- GROUP
- MAP_REDUCE
- DISTINCT_FIELD
- GEO_LOCATION

Expand Down Expand Up @@ -330,47 +328,6 @@ in the order you call the method:
$query->sort('featured', 'desc');
Map Reduce
~~~~~~~~~~

You can also run map reduced find queries using the ``Query``
object:

.. code-block:: php
<?php
$qb = $this->dm->createQueryBuilder(Event::class)
->field('type')->equals('sale')
->map('function() { emit(this.userId, 1); }')
->reduce("function(k, vals) {
var sum = 0;
for (var i in vals) {
sum += vals[i];
}
return sum;
}");
$query = $qb->getQuery();
$results = $query->execute();
.. note::

When you specify a ``map()`` and ``reduce()`` operation
the results will not be hydrated and the raw results from the map
reduce operation will be returned.

If you just want to reduce the results using a javascript function
you can just call the ``where()`` method:

.. code-block:: php
<?php
$qb = $dm->createQueryBuilder(User::class)
->where("function() { return this.type == 'admin'; }");
You can read more about the `$where operator <https://docs.mongodb.com/manual/reference/operator/query/where/>`_ in the Mongo docs.

Conditional Operators
~~~~~~~~~~~~~~~~~~~~~

Expand Down Expand Up @@ -923,38 +880,3 @@ Here is an example where we remove users who have never logged in:
->field('num_logins')->equals(0)
->getQuery()
->execute();
Group Queries
-------------

.. note::

Due to deprecation of ``group`` command in MongoDB 3.4 the ODM
also deprecates its usage through Query Builder in 1.2. Please
use :ref:`$group stage <aggregation_builder_group>` of the
Aggregation Builder instead.

The last type of supported query is a group query. It performs an
operation similar to SQL's GROUP BY command.

.. code-block:: php
<?php
$result = $this->dm->createQueryBuilder(\Documents\User::class)
->group([], ['count' => 0])
->reduce('function (obj, prev) { prev.count++; }')
->field('a')->gt(1)
->getQuery()
->execute();
This is the same as if we were to do the group with the raw PHP
code:

.. code-block:: php
<?php
$reduce = 'function (obj, prev) { prev.count++; }';
$condition = ['a' => ['$gt' => 1]];
$result = $collection->group([], ['count' => 0], $reduce, $condition);
1 change: 0 additions & 1 deletion docs/en/sidebar.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
reference/find-and-update
reference/filters
reference/priming-references
reference/map-reduce
reference/capped-collections
reference/storage-strategies
reference/custom-collections
Expand Down
Loading

0 comments on commit 280e05e

Please sign in to comment.