1

I am new to mongodb concepts. I am trying to get documents from one collection in MongoDB through PHP Phalcon's ODM and more specifically the "aggregate" method of Phalcon\Mvc\Collection. The MySQL equivalent of what I'm trying to do looks like this:

SELECT * FROM nodes WHERE timestamp >= X AND timestamp < Y AND user_id = 25 
AND (type = "classic" OR type = "new")

It is pretty simple (for MySQL)

MondoDB's documentation helps, but understanding what Phalcon expects for input to the "aggregate" method seems unclear to me while reading this https://docs.phalconphp.com/en/latest/reference/odm.html#aggregations

I also tried the "find" method of Phalcon\Mvc\Collection, but it either throws errors or returns documents that don't match the conditions.

Ultimater
  • 4,647
  • 2
  • 29
  • 43
harv3s7er
  • 73
  • 6
  • 1
    You aren't calculating stuff so you don't need to use the "aggregate" function. What error(s) did you get while using the "find" method? – Timothy Oct 03 '16 at 09:22

1 Answers1

0

You haven't given any code that you have tried which makes it a bit harder to understand what you are trying to achieve. However, would something like this work?

$nodes = NodesCollection::find([
    [
        'timestamp' => [
            '$gte' => X,
            '$lt'  => Y
        ],
        'user_id' => 25
    ]
]);

The key thing to note from this example is the use of Mongo comparison operators. You can learn more about these here: https://docs.mongodb.com/manual/reference/operator/query-comparison/

Armon Bigham
  • 339
  • 2
  • 14