Skip to content

Instantly share code, notes, and snippets.

@cessor
Created February 5, 2014 08:42
Show Gist options
  • Select an option

  • Save cessor/8819469 to your computer and use it in GitHub Desktop.

Select an option

Save cessor/8819469 to your computer and use it in GitHub Desktop.
def both(a,b):
return equals('$and', [a,b])
def exists(fieldname):
d = {}
d[str(fieldname)] = {'$exists': True }
return d
def equals(fieldname, value):
d = {}
d[str(fieldname)] = value
return d
# 'in' is a python keyword
def contains(fieldname, array):
d = {}
d[str(fieldname)] = {'$in': array}
return d
def not_in(fieldname, array):
d = {}
d[str(fieldname)] = {'$nin': array}
return d
def combine(*docs):
d = {}
for doc in docs:
d.update(doc)
return d
def update(fieldname, value):
return { '$set': { str(fieldname): value}}
def _get(fieldname):
return { str(fieldname): True }
def by(key):
return equals(ID, key)
class Is(object):
def __init__(self, value):
self.value = value
def __getattr__(self, name):
return equals(name, self.value)
true = Is(True)
false = Is(False)
class Get(object):
def __call__(self, fieldname):
return _get(fieldname)
def __getattr__(self, fieldname):
return _get(fieldname)
get = Get()
ID = '_id'
pk = get(ID)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment