- MongoEngine - Discussion
- MongoEngine - Useful Resources
- MongoEngine - Quick Guide
- MongoEngine - Extensions
- MongoEngine - Text Search
- MongoEngine - Signals
- MongoEngine - GridFS
- MongoEngine - Javascript
- MongoEngine - Atomic Updates
- MongoEngine - Document Inheritance
- MongoEngine - Advanced Queries
- MongoEngine - Aggregation
- MongoEngine - Indexes
- MongoEngine - Custom Query Sets
- MongoEngine - Sorting
- MongoEngine - QuerySet Methods
- MongoEngine - Query Operators
- MongoEngine - Filters
- MongoEngine - Querying Database
- MongoEngine - Add/Delete Document
- MongoEngine - Fields
- MongoEngine - Dynamic Schema
- MongoEngine - Document Class
- MongoEngine - Connecting to MongoDB Database
- MongoEngine - Installation
- MongoEngine - Object Document Mapper
- MongoEngine - MongoDB Compass
- MongoEngine - MongoDB
- MongoEngine - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
MongoEngine - Extensions
MongoEngine integrates beautifully with the following pbraries −
marshmallow_mongoengine
marshmallow is an ORM/ODM/framework independent seriapzation/deseriapzation pbrary for converting complex datatypes, such as objects, to and from native Python datatypes. Using this extension of MongoEngine, we can easily perform seriapze/deseriapze operations.
First, create a Document class as usual as follows −
import mongoengine as me class Book(me.Document): title = me.StringField()
Then generate marshmallow schema with the code below −
from marshmallow_mongoengine import ModelSchema class BookSchema(ModelSchema): class Meta: model = Book b_s = BookSchema()
Save a document using the code:
book = Book(title= MongoEngine Book ).save()
And perform seriapzation/deseriapzation using dump(0 and load() using the code below −
data = b_s.dump(book).data b_s.load(data).data
Flask-MongoEngine
This is a Flask extension that provides integration with MongoEngine. Connection management of MongoDB database for your app is handled easily by this pbrary. You can also use WTForms as model forms for your models.
After installation of flask-mongoengine package, initiapze flask app with the following settings −
from flask import Flask from flask_mongoengine import MongoEngine app = Flask(__name__) app.config[ MONGODB_SETTINGS ] = { db : mydata , host : localhost , port :27017 } db = MongoEngine(app)
Then define a Document sub class using the below code −
class book(me.Document): name=me.StringField(required=True)
Declare an object of above class and call save() method when a particular route is visited.
@app.route( / ) def index(): b1=book(name= Introduction to MongoEngine ) b1.save() return success
extras-mongoengine
This extension contains additional Field Types and any other wizardry.
Eve-MongoEngine
Eve is an open source Python REST API framework designed for human beings. It allows to effortlessly build and deploy highly customizable, fully featured RESTful Web Services.
Eve is powered by Flask and Cerberus and it offers native support for MongoDB data stores. Eve-MongoEngine provides MongoEngine integration with Eve.
Install and import the extension using the code below −
import mongoengine from eve import Eve from eve_mongoengine import EveMongoengine
Configure the settings and initiapze the Eve instance.
my_settings = { MONGO_HOST : localhost , MONGO_PORT : 27017, MONGO_DBNAME : eve_db app = Eve(settings=my_settings) # init extension ext = EveMongoengine(app)
Define a Document class as shown below −
class Person(mongoengine.Document): name = mongoengine.StringField() age = mongoengine.IntField()
Add the model and run the apppcation, finally using the below code −
ext.add_model(Person) app.run()
Django-MongoEngine
This extension aims to integrate MongoEngine with Django API, a very popular Python web development framework. This project is still under development.
Advertisements