MongoEngine – MongoDB Compass


MongoEngine – MongoDB Compass



”;


MongoDB has also developed a GUI tool for handling MongoDB databases. It is called MongoDB Compass. It is a convenient tool for performing all CRUD operations without manually writing queries. It helps in many activities such as indexing, document validation, etc.

Download community edition of MongoDB Compass from https://www.mongodb.com/download-center/compass and start MongoDBCompassCommunity.exe (Ensure that MongoDB server is running before starting Compass). Connect to the local server by giving correct host and port number.


Databases

All the databases currently available will be listed as below −


New Database

Click on + button (shown at the bottom of left panel) to create new database.


Name of Database

Choose name of database from list and select a Collection as shown below −


CSV or JSON file

You can add document directly or import from CSV or JSON file.


Insert Document

Choose Insert Document from Add data drop down.


Documents added

Documents added will be displayed in JSON, list or tabular form −


Relational Database

Note that, just as a table in relational database has a primary key, document in MongoDB database has a special key called “_id” that is automatically generated.

MongoDB Inc. provides a Python driver for connection with MongoDB databases. It is called PyMongo whose usage is similar to standard SQL queries.

After installing PyMongo module, we need object of MongoClient class for interacting with MongoDB server.


<<< from pymongo import MongoClient
<<< client=MongoClient() 

New database is created with the following statement −


db=client.mydatabase 

CRUD operations on this database are performed with methods such as insert_one() (or insert_many()), find(), update() and delete() methods. Detailed discussion of PyMongo library is available at https://www.tutorialspoint.com/python_data_access/python_mongodb_introduction.htm.

However, Python’s user defined objects cannot be stored in database unless it is converted in MongoDB’s data types. This is where we need MongoEngine library.

Advertisements

”;

Leave a Reply

Your email address will not be published. Required fields are marked *