Skip to content

Querying specific fields through the Mongo ODM

Koen Calliauw edited this page Nov 19, 2013 · 1 revision

At the time of writing this, it's not well documented how to query specific fields from a MongoDB database using the Phalcon ODM. Below is a quick description on how to accomplish this.

$myRobots = Robots:find(array(
        "fields" => array("name" => 1)
    )
);

The above find() only returns the name. It can be combined with a condition as well. Below only returns the name of the robots with type = maid.

$myRobots = Robots:find(array(
        array("type" => "maid"),
        "fields" => array("name" => 1)
    )
);
Clone this wiki locally