This test application provide feature to use SQL SELECT
operator with MongoDB.
- PHP 7.0
- MongoDB driver (See MongoDB PHP Driver Installation)
composer
command (See Composer Installation)
$ composer install
Above command install dependencies and prepare environment for testing.
To configure MongoDB connection you need to rename app/config/config.yml.dist
to app/config/config.yml
and put into this file your credentials:
mongodb:
username: '[username]'
password: '[password]'
host: 'localhost'
port: 27017
database: '[database]'
# From project root execute command
$ php mongo-sql
# Get data from collection
> SELECT * FROM collection_name;
# Select specific fields(templates: *, field, field.subfield, field.*) separated by commas
> SELECT field FROM collection_name;
# Use WHERE condition to extract only those records that fulfill a specified condition
> SELECT field FROM collection_name WHERE size > 10;
# Sort result
> SELECT field FROM collection_name ORDER BY age DESC, name;
# Use SKIP to control where MongoDB begins returning results
> SELECT field FROM collection_name SKIP 3;
# Use LIMIT to specify the maximum number of documents the cursor will return.
> SELECT field FROM collection_name LIMIT 5;
- mongodb: MongoDB driver library
- php-di: Dependency Injection Container for PHP
- yaml: Symfony Yaml Component for pretty config files
- phpunit: Testing framework for PHP
$ phpunit