akkroo / phpmongoquery
Mongo queries in PHP
Installs: 5 799
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 17
Forks: 0
Open Issues: 0
Requires
- php: >=5.3.0
- psr/log: ~1.0
Requires (Dev)
- monolog/monolog: 1.*
- phpunit/phpunit: 4.6.*
This package is auto-updated.
Last update: 2024-11-15 20:42:08 UTC
README
Mongo queries in PHP
PHPMongoQuery implements MongoDB queries in PHP, allowing developers to query a 'document' (an array containing data) against a Mongo query object, returning a boolean value for pass or fail. Additionally a set of documents can be queried to filter them, as queries are used in MongoDB.
This code is used at Akkroo to allow the construction of advanced form logic queries in the form field definition.
Usage
<?php use Akkroo\PHPMongoQuery; $query = array('a' => 'foo', 'b' => array('$ne' => 'bar')); $document = array( 'id' => 1, 'a' => 'foo', 'b' => 'barr' ); var_dump(PHPMongoQuery::executeQuery($query, $document));
This will output
bool(true)
Methods
find($query, $documents, $options)
Perform a query on a set of documents to filter out only those which pass the query
executeQuery($query, $documents, $options)
Execute a query on a single document, returning a boolean value for pass or fail
appendFieldSpecifier($query, $append)
Append a field specifier to any field queries. For example, your query may have been written as follows:
$query = array('a' => 'foo');
However, the actual document structure is
$document = array('a' => array('value' => 'foo'), 'b' => array('value' => 'bar'));
So you need to append the 'value' specifier to the query field specifiers for the query to work. For example:
$newQuery = PHPMongoQuery::appendFieldSpecifier($query, 'value');
// $newQuery is array('a.value' => 'foo');
getDependentFields($query)
Parse a query to find all the fields it depends on. This is useful for listening to when those values change, so the query is only repeated when the result could have changed. For example:
$query = array('a' => 'foo');
$dependentFields = PHPMongoQuery::getDependentFields($query);
// $dependentFields is array('a');