A
A
Alexey Poloz2017-10-28 14:55:53
Python
Alexey Poloz, 2017-10-28 14:55:53

Python MongoDB How to get last added element?

How to get the last added element to a collection without reading the entire collection?
And it will be even better if you tell me if it is possible to get the element with the largest value of the given field, again without reading the entire collection, those are just the mongodb command in python

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vlad, 2017-10-28
@kosyachniy

db.collection.find().sort({$natural: -1}).limit(1)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question