The runtime engine is an ODM (Object-DocumentMapper) Framework of MongoDB. It provides a syntax similar to Django to operate MongoDB databases. Install PyMongo before installing the external engine. Use pip to install $ [sudo] pipinstallmongoengine through source code. First download the source code from PyPi or Github.
The runtime engine is an ODM (Object-Document Mapper) Framework of MongoDB. It provides a syntax similar to Django to operate MongoDB databases. Install PyMongo before installing the external engine. Use pip to install $ [sudo] pip install external engine through source code first download the source code from PyPi or Github
The runtime engine is an ODM (Object-Document Mapper) Framework of MongoDB. It provides a syntax similar to Django to operate MongoDB databases.
Install
Install PyMongo before installing external engine.
Install using pip
$ [sudo] pip install mongoengine
Install with source code
Download the source code from PyPi or Github. Then install the SDK.
$ [sudo] python setup.py install
Use
Start the mongodb server first:
$ mongod
Connect to the server
Using the connect Method for database connection is similar to pymongo in usage. Its parameters can be of multiple types.
from mongoengine import connectconnect('project1')connect('project1', host='mongodb://localhost:27017/test_database')
Multi-database support has been added since Runtime Engine 0.6. The second parameter of connect can be set to an alias for each link.
Define data models
The Document of movie engine is similar to the django Model.
class User(mongoengine.Document): name = mongoengine.StringField() meta = {"db_alias": "default"}
Data Operations
The data addition process is similar to django:
User.objects.create(name="test1")User.objects.create(name="test2")User(name="test3").save()
Query data:
User.objects.filter(name="test2")
Delete data:
User.objects.filter(name="test2").delete()
Although the external engine provides ODM, we can still directly operate the database.
Get collection object of pymongo:
User.objects._collection
Then you can use the native pymongo operation.
Original article address: tutorial engine (1)-Overview, thanks to the original author for sharing.