📅  最后修改于: 2023-12-03 15:32:57.531000             🧑  作者: Mango
Mongoengine is a Python Object-Document Mapper (ODM) for working with MongoDB. It provides a clean and pythonic API for querying and performing CRUD operation on MongoDB collections.
You can install mongoengine using pip:
pip install mongoengine
from mongoengine import connect
connect('my_database', host='localhost', port=27017)
from mongoengine import Document, StringField
class User(Document):
name = StringField()
email = StringField()
user = User(name='John Doe', email='john.doe@example.com')
user.save()
user = User.objects(name='John Doe').first()
user.email = 'john.doe.update@example.com'
user.save()
users = User.objects(email__contains='example.com')
for user in users:
print(user.name, user.email)
Mongoengine is a powerful tool for working with MongoDB in Python. It provides a clean and pythonic API for querying and performing CRUD operation on MongoDB collections.