/mdb-sf-demo

MongoDB Symfony demo

Primary LanguagePHP

mdb-sf-demo

A very basic MongoDB Symfony demo to showcase persistance of object as JSON into MongoDB through Symfony PHP framework and MongoDB PHP driver.

Here are the steps I followed on my macOS Catalina (version 10.15.7):

Install package / dependency manager for PHP

brew install composer

Install PHP

brew install php

At the time of writing this the version installed on my macOS is 8.0.8

Install MongoDB PHP driver

sudo pecl install mongodb

Install Symfony

curl -sS https://get.symfony.com/cli/installer | bash
mv /Users/hjournea/.symfony/bin/symfony /usr/local/bin/symfony

Git clone the demo source code

mkdir Repositories/mdb-sf-demo
cd Repositories/mdb-sf-demo
git clone https://github.com/hourdays/mdb-sf-demo.git .

Install project dependecies especially Doctrine, the object document mapper (ODM)

composer require doctrine/mongodb-odm-bundle

composer install

Launch the server locally

symfony server:start

Specify the MongoDB Atlas connection string inside .env

Replace the following with your own connection string specifications provided by MongoDB Atlas GUI as pictured herefater.

###> doctrine/mongodb-odm-bundle ###
MONGODB_URL=mongodb+srv://<username>:<password>@demo.130he.mongodb.net/?retryWrites=true&w=majority
MONGODB_DB=eazy
###< doctrine/mongodb-odm-bundle ###

Go to http://127.0.0.1:8000/createProduct to create a Product

View the created product with MongoDB Compass:

Go to http://127.0.0.1:8000/showProduct/611cf14b8e2d9df2ff03a334 to get Product with _id 611cf14b8e2d9df2ff03a334