MONGODB

MongoDB stores data records as BSON documents. BSON is a binary representation of JSON documents, though it contains more data types than JSON.

MongoDB documents are composed of field-and-value pairs and have the following structure:

MONGODB INSTALLATION

  1. Import the public key used by the package management system.

  2. Create a list file for MongoDB.

  3. Reload local package database.

  4.  Install the MongoDB packages.

START MONGODB SERVICE

  1. Start MongoDB

    Verify that the mongod process has started successfully by checking the contents of the log file at /var/log/mongodb/mongod.log  for a line reading
  2. To Enter Mongo Shell
  3. Stop MongoDB

 

MONGO WITH EVE (PYTHON)

we’ll see how to build REST APIs using the EVE framework based on Flask, MongoDB and Redis. Eve allows to effortlessly build and deploy highly customizable, fully featured RESTful Web Service.

INSTALALTION

The API should be running on:

 

Using the API to use MongoDB

  1. Inserting a data to the collection user
  2. Getting data from a collection

    It gives the output
  3. Updating a data

    Make sure to replace the object id of your document in the request (http://localhost:5000/user/{oid}).
    We need to provide the _etag value in the header to edit a document with the updating fields.
    Note: The _etag value is available in the document.
  4. Deleting a data

     

CONCLUSION

We saw how to get started with creating a REST API using the Python EVE framework. We created some basic APIs for CRUD operations for a collection in the MongoDB.