October 2018
Intermediate to advanced
332 pages
8h 9m
English
If you know the exact value of the field you wish to filter by, then you can pass its value as a keyword to the objects method, as follows:
>>> Post.objects(title="Post From The Console").first() <Post: "Post From The Console">
Unlike SQLAlchemy, we cannot pass truth tests to filter our results. Instead, special keyword arguments are used to test values. For example, to find all posts published after January 1 2015, enter the following:
>>> Post.objects(
publish_date__gt=datetime.datetime(2015, 1, 1)
).all()
[<Post: "Post From The Console">]
The __gt appended to the end of the keyword is called an operator. MongoEngine supports the following operators: