PHP code example of exs / simple-mongo-bundle

1. Go to this page and download the library: Download exs/simple-mongo-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

exs / simple-mongo-bundle example snippets

 php
//app/AppKernel.php
//...
public function registerBundles()
{
    $bundles = array(
    //Other bundles
    new EXS\SimpleMongoBundle\EXSSimpleMongoBundle(),
);
 php
    simple_mongo:
        connection: mongodb://localhost:27017
        dbname: YOUR_DB_NAME
 php
// Insert data to mongodb
$entity = new YourEntity();
$entity->setPropertyValue(THE_VALUE);
.
.

$manager = $this->get('exs_simple_mongo.service'); // get the service
$manager->persist($entity);   
$result = $manager->flush(COLLECTION_NAME); // the result will store the number of inserted entries or error message
if(!is_int($result) || $result == 0) {
    throwException($result);
}

// Update
$filter = ['product' => 6];
$manager->update($filter, $entity);   
$result = $manager->flush(COLLECTION_NAME); 
 
// Get data with query
$filter = ['product' => 6];
$option = ['projection' => ['_id' => 0]];

$manager = $this->get('exs_simple_mongo.service'); // get the service
$result = $manager->exeQuery($filter, $option, COLLECTION_NAME);
// $result will contain results in an array