English 中文(简体)
MongoEngine - MongoDB Compass
  • 时间:2024-11-03

MongoEngine - MongoDB Compass


Previous Page Next Page  

MongoDB has also developed a GUI tool for handpng 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 vapdation, 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 psted as below −

New Database

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

Name of Database

Choose name of database from pst 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, pst 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 instalpng PyMongo module, we need object of MongoCpent class for interacting with MongoDB server.


<<< from pymongo import MongoCpent
<<< cpent=MongoCpent() 

New database is created with the following statement −


db=cpent.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 pbrary 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 pbrary.

Advertisements