A
A
Almat Nygman2016-08-16 17:42:07
Python
Almat Nygman, 2016-08-16 17:42:07

MongoDB pymongo how to display records in descending order?

How to display entries in descending order? In sql it's like this: SELECT* FROM posts ORDER BY id DESC. And how is this implemented in MongoDB pymongo?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vlad_Fedorenko, 2016-08-16
@almatalmat

from pymongo import MongoClient, ASCENDING, DESCENDING
con = MongoClient('localhost:27017')
for x in con.db.collection.find( {'field' : 'value'} ).sort([('student_id', ASCENDING)]):
    print x

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question