New last document inserted python api

i insert the document like above example. I have a trigger counter in this part :slight_smile:

“fileId”: {
“$numberLong”: “1”

How can i know the number of the last document inserted?

{
  "_id": {
    "$oid": "625dba6f6ee73e4f6bbd7f15"
  },
  "insertionData": "18/04/2022 20:22:21",
  "ipfsMetadata": {
    "Name": "data2.json",
    "Hash": "Qmaxu6XaioktMvrwbvyeeLMiAUBZDiyXdUAibPViCQhvcS",
    "Size": "390"
  },
  "metadata": {
    "userSent": "user123",
    "userId": "user123",
    "birthdate": "",
    "height": "",
    "weight": "",
    "poolsize": "",
    "modality": "",
    "swimStyle": "",
    "gender": "gender",
    "gender-title": "gender-title"
  },
  "fileId": {
    "$numberLong": "1"
  }
}

Can you explain what you mean by this? It sounds like you’re saying some trigger sets this field value but there’s no such built-in capability in MongoDB Server, so without knowing what is setting the count it’s hard to answer how you can get it back. Unless you mean you want the document with the highest fileId value in which case you can query the collection with sort and limit to get it.

Asya