# {'a': 1, 'b': 1} # {'a': 3, 'b': 3} # {'a': 1, 'b': 4} # {'a': 3, 'b': 6} for doc in db.docs.find(q(a=_ne(2))): del doc['_id'] print(doc) print() # {'a': 1, 'b': 4} # {'a': 2, 'b': 5} # {'a': 3, 'b': 6} for doc in db.docs.find(q(b=_gt(3))): del doc['_id'] print(doc) print() # {'a': 2, 'b': 2} # {'a': 3, 'b': 3} # {'a': 3, 'b': 6} for doc in db.docs.find(q(a=3) | q(b=2)): del doc['_id'] print(doc) print() # {'a': 1, 'b': 4} for doc in db.docs.find(_and(q(a=1), q(b=4))): del doc['_id'] print(doc) print()
def test_query_and_query(): q1 = q({'a': 1, 'b': 2}) q2 = q({'a': 1, 'c': 3}) assert q1 & q2 == _and(q1, q2)
def test_and(): query = q(_and({'a': 1}, {'b': 2})) assert query == {'$and': [{'a': 1}, {'b': 2}]}