From dc3ada65a5ccff8809b88a8fe98ea3a76fa4ba58 Mon Sep 17 00:00:00 2001 From: Klimov Paul Date: Thu, 28 Nov 2013 20:36:38 +0200 Subject: [PATCH] Mongo query "IN" condition shortcut syntax added. --- extensions/mongo/Collection.php | 8 +++++++- tests/unit/extensions/mongo/QueryRunTest.php | 4 +--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/extensions/mongo/Collection.php b/extensions/mongo/Collection.php index 7292348..5f7246c 100644 --- a/extensions/mongo/Collection.php +++ b/extensions/mongo/Collection.php @@ -242,7 +242,13 @@ class Collection extends Object if (is_numeric($key)) { $result[] = $actualValue; } else { - $result[$this->normalizeConditionKeyword($key)] = $actualValue; + $key = $this->normalizeConditionKeyword($key); + if (strncmp('$', $key, 1) !== 0 && array_key_exists(0, $actualValue)) { + // shortcut for IN condition + $result[$key]['$in'] = $actualValue; + } else { + $result[$key] = $actualValue; + } } } return $result; diff --git a/tests/unit/extensions/mongo/QueryRunTest.php b/tests/unit/extensions/mongo/QueryRunTest.php index b36851a..f8821b6 100644 --- a/tests/unit/extensions/mongo/QueryRunTest.php +++ b/tests/unit/extensions/mongo/QueryRunTest.php @@ -75,9 +75,7 @@ class QueryRunTest extends MongoTestCase $query = new Query; $rows = $query->from('customer') ->where([ - 'name' => [ - 'in' => ['name1', 'name5'] - ] + 'name' => ['name1', 'name5'] ]) ->all($connection); $this->assertEquals(2, count($rows));