@@ 258-271 (lines=14) @@ | ||
255 | * @param \Sokil\Mongo\Expression|callable|array $expression |
|
256 | * @return \Sokil\Mongo\Expression |
|
257 | */ |
|
258 | public function whereElemMatch($field, $expression) |
|
259 | { |
|
260 | if(is_callable($expression)) { |
|
261 | $expression = call_user_func($expression, $this->expression()); |
|
262 | } |
|
263 | ||
264 | if($expression instanceof Expression) { |
|
265 | $expression = $expression->toArray(); |
|
266 | } elseif(!is_array($expression)) { |
|
267 | throw new Exception('Wrong expression passed'); |
|
268 | } |
|
269 | ||
270 | return $this->where($field, array('$elemMatch' => $expression)); |
|
271 | } |
|
272 | ||
273 | /** |
|
274 | * Matches documents in a collection that contain an array field with elements |
@@ 52-65 (lines=14) @@ | ||
49 | * @return \Sokil\Mongo\Pipeline |
|
50 | * @throws \Sokil\Mongo\Exception |
|
51 | */ |
|
52 | public function match($expression) |
|
53 | { |
|
54 | if (is_callable($expression)) { |
|
55 | $expressionConfigurator = $expression; |
|
56 | $expression = new Expression(); |
|
57 | call_user_func($expressionConfigurator, $expression); |
|
58 | $expression = $expression->toArray(); |
|
59 | } elseif (!is_array($expression)) { |
|
60 | throw new Exception('Must be array or instance of Expression'); |
|
61 | } |
|
62 | ||
63 | $this->addStage('$match', $expression); |
|
64 | return $this; |
|
65 | } |
|
66 | ||
67 | /** |
|
68 | * Passes along the documents with only the specified fields to the next |