How to save the cursor location locally when python traverses mongodb

there is a requirement in the project that a field extracted from the mongodb library at the level of tens of millions of records needs to be transferred to postgresql.
because the mongodb is constantly updated, the data needs to be reversed at regular intervals. So I want to achieve the function of incremental update.
the question is, how do I save the location where I traversed the last python?

The _ id field of

ps:mongodb is automatically generated, and the other fields do not have a strict increasing or decreasing quantity relationship.

Mar.03,2021

if the _ id field in the document is automatically generated by mongo, then the field itself has a timing, because the ObjectId four elements
have insertion time, nothing is written in the query statement, and the result is sorted in chronological order. The following statement returns the last 10 pieces of data in collection:

  python datetime 

					
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b368c6-2c005.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b368c6-2c005.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?