Last active
December 16, 2015 14:29
-
-
Save neumino/5449011 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Query 1 | |
cursor = r.db('test').table('test').filter(lambda doc: | |
(doc['status'] == 'open') & doc['baseaddresses'].map(lambda address: address == 'sathis...@example.org').reduce(lambda acc, val: acc | val) ).order_by('date').run() | |
for doc in cursor: | |
print doc | |
# Query 2 | |
cursor = r.db('test').table('test').filter(lambda doc: ((doc['status'] == 'open') | (doc['status'] == 'paused')) & doc['baseaddresses'].map(lambda address: address == 'sathis...@example.org').reduce(lambda acc, val: acc | val) ).order_by('date').run() | |
for doc in cursor: | |
print doc | |
# Bonus - If you want 3 results per page, each time you can your page, you increment start_page and it's going to return the next 3 results. | |
start_page = 0 | |
cursor = r.db('test').table('test').filter(lambda doc: ((doc['status'] == 'open') | (doc['status'] == 'paused')) & doc['baseaddresses'].map(lambda address: address == 'sathis...@example.org').reduce(lambda acc, val: acc | val) ).order_by('date').skip(page_start*3).limit(3).run() | |
for doc in cursor: | |
print doc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You could also do for the array matching:
cursor = r.db('test').table('test').filter(lambda doc:
(doc['status'] == 'open') & (doc['baseaddresses'].filter(lambda address: address == 'sathis...@example.org').count() > 0) ).run()
As a side note, we're planning to simplify the array matching part (and we already have some very good proposals for how to do it, but it will take a bit before it will get implemented)