- MongoEngine Tutorial
- MongoEngine - Home
- MongoEngine - MongoDB
- MongoEngine - MongoDB Compass
- MongoEngine - Object Document Mapper
- MongoEngine - Installation
- MongoEngine - Connecting to MongoDB Database
- MongoEngine - Document Class
- MongoEngine - Dynamic Schema
- MongoEngine - Fields
- MongoEngine - Add/Delete Document
- MongoEngine - Querying Database
- MongoEngine - Filters
- MongoEngine - Query Operators
- MongoEngine - QuerySet Methods
- MongoEngine - Sorting
- MongoEngine - Custom Query Sets
- MongoEngine - Indexes
- MongoEngine - Aggregation
- MongoEngine - Advanced Queries
- MongoEngine - Document Inheritance
- MongoEngine - Atomic Updates
- MongoEngine - Javascript
- MongoEngine - GridFS
- MongoEngine - Signals
- MongoEngine - Text Search
- MongoEngine - Extensions
- MongoEngine Useful Resources
- MongoEngine - Quick Guide
- MongoEngine - Useful Resources
- MongoEngine - Discussion
MongoEngine - Filters
The objects attribute is a QuerySet manager. It creates and returns a QuerySet when accessed. A query can be subjected to filter with the help of field names as keyword arguments. For example, from above products collection, to print details of document with name of product as ‘TV’, we use Name as keyword argument.
for product in products.objects(Name='TV'): print ('ID:',product.ProductID, 'Name:',product.Name, 'Price:',product.price)
You can use filter method of QuerySet object to apply filter to query. Following code snippet also returns product details with name=’TV’.
qset=products.objects for product in qset.filter(Name='TV'): print ('ID:',product.ProductID, 'Name:',product.Name, 'Price:',product.price)
Advertisements