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