Skip to content

fletom/pymongo_query

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 

Repository files navigation

PyMongo Query

PyMongo Query is a tiny library that overloads several operators to make writing PyMongo-compatible MongoDB queries a lot nicer.

Usage

You can do:

>>> User.find((k('username') == 'fletom') | (k('name').starts_with('Fletcher')))
...
>>> User.find(k('reputation') > 10)
...

Instead of:

>>> User.find({'$or': [{'username': 'fletom'}, {'name': {'$regex': '^Fletcher'}}]})
...
>>> User.find({'reputation': {'$gt': 10}})
...

Documentation

There's not much to it. The k objects support all of Python's comparison operators, in addition to .starts_with(s) and .ends_with(s). PyMongoQuery is a dict subclass that supports logical and and or using the & and | syntax. If you think a feature should be added, feel free to send in a pull request.

About

A tiny Python library for writing more expressive MongoDB queries.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages