Tutorial engine (1) Overview

Source: Internet
Author: User
Tags mongodb server
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.