Skip to content

How to limit result set? #384

Answered by therden
Kolos65 asked this question in Q&A
Mar 17, 2021 · 3 comments · 2 replies
Discussion options

You must be logged in to vote

Assuming that you're using the default JSONStorage and that you haven't set sort_keys=True, then (since db.all() returns a list of dicts), you can slice the results:

db.all()[-10:] # will return a list of the ten most recently inserted documents
db.all()[-3:] # will return a list of the three most recently inserted documents

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@Kolos65
Comment options

@therden
Comment options

Answer selected by Kolos65
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants