Skip to content

LintangWisesa/CRUD_Flask_MongoDB

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

simplinnovation

Basic CRUD: Flask & MySQL

  1. Activate MongoDB server:

    $ cd C:\Program Files\MongoDB\Server\3.6\bin
    $ mongod

    Open new terminal & type again:

    $ cd C:\Program Files\MongoDB\Server\3.6\bin
    $ mongo

    [OPTIONAL] You can create a database & collection first, or let our Flask application do this later. If you wanna create db & col first, do these on Mongo:

    > use lin_flask
    > db.createUser({user:'lintang', pwd:'1234', roles:['readWrite', 'dbAdmin']})
    > db.createCollection('users')

  1. Clone this repo. Insert your database URI to database.yaml file, then install all the packages needed. In this project I'm using flask, flask_cors & pymongo:
    $ git clone https://github.com/LintangWisesa/CRUD_Flask_MongoDB.git
    $ cd CRUD_Flask_MongoDB
    $ pip install flask flask_cors pymongo

  1. Run the server file. Make sure your MongoDB server is still running. Your application server will run locally at http://localhost:5000/ :
    $ python app.py

  1. Give a request to the server. You can use Postman app:

    See the opening screen (home.html)

    GET /

    Post a data to database:

    POST /data
    body request: {name:"x", age:"y"}

    Get all data & specific data by MongoDB ObjectId:

    GET /data
    GET /data/{:id}

    Update a data by MongoDB ObjectId:

    PUT /data/{:id}
    body request: {name:"x", age:"y"}

    Delete a data by MongoDB ObjectId:

    DELETE /data/{:id}

  1. Enjoy your code! 😎👌

See also:

Lintang Wisesa 💌 lintangwisesa@ymail.com

Facebook | Twitter | Google+ | Youtube | :octocat: GitHub | Hackster

About

Basic CRUD with Python Flask & MongoDB Database

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published