How does mongodb realize the self-increment of a field when inserting new data?

  mongodb, question

Like mysql, I remember that when new data is inserted, the id can be automatically increased.
Can mongodb be implemented? How do I set the table if I can?

Reason:
There is a scheduled task list, there arebeginTime, endTime, areaThree fields,
When the node service is started, I first look up all the data in the database and then set the timing tasks one by one.

However, when the scheduled task is manually cancelled by others on the webpage (the data in the database is deleted), I need to clear the task while deleting it.
So I thought of adding a fieldnameSuch as field, on behalf of his variable name, when the time comes to delete, calleval(name).clear().

After so many withdrawals.

Question:

  1. Can mongodb realize the self-increment of a certain field when adding data?
  2. Is there any other way to achieve the scheduled task I want?

In general, mongodb automatically inserts a unique _id field as pk

If you really want to increase, you can refer tohttps://docs.mongodb.com/v3.0 …

In short, it is:

  1. Create a self-increasing counter
  2. Create a function to update the counter with findAndModify (use $inc for self-increment during update)
  3. When inserting a record, use this function to obtain a self-increasing ID

As for the scheduled task you mentioned, I’m sorry I didn’t understand it.