Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Simple Mongo Bundle Laravel Package

exs/simple-mongo-bundle

View on GitHub
Deep Wiki
Context7

EXS-SimpleMongoBundle

A simple bundle to persist and execute queries on MongDB database for php7

Installing the # EXS-SimpleMongoBundle in a new Symfony2 project

Edit composer.json file with # EXS-SimpleMongoBundle dependency:

//composer.json
//...
"require": {
    //other bundles
    "exs/simple-mongo-bundle": "^1.0"
},

Save the file and have composer update the project via the command line:

composer update exs/simple-mongo-bundle

Update the app/AppKernel.php

//app/AppKernel.php
//...
public function registerBundles()
{
    $bundles = array(
    //Other bundles
    new EXS\SimpleMongoBundle\EXSSimpleMongoBundle(),
);

Usage

Add your mongodb connection and dbname in the parameter file

    simple_mongo:
        connection: mongodb://localhost:27017
        dbname: YOUR_DB_NAME

Create the new collection(Optional)

app/console exs:create:collection COLLECTION_NAME(Requires) OPTIONS
// Options
app/console exs:create:collection -h

In your controller or service

// 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

Contributing

Anyone and everyone is welcome to contribute.

If you have any questions or suggestions please let us know.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log
gregsphotography/site-builder-components
io-digital/clickatell
snowsoft/laravel-admin
oxygen/auth
relicsoftware/barakah-payment-gateway
tobya/work-with-composer
equipc/laravel-email-validator
equipc/laravel-email-database-log
adedsec/nova-translated-labels
wazza/laravel-db-encryption
hokny/laravel-generator
vonsogt/backup
jengo/queues
jeremykenedy/laravel-observability
coleus/frame
thtg88/journalism
filagora/filagora-ai-forums