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?
There is a scheduled task list, there are
beginTime, 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 field
nameSuch as field, on behalf of his variable name, when the time comes to delete, call
After so many withdrawals.
- Can mongodb realize the self-increment of a certain field when adding data?
- 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:
- Create a self-increasing counter
- Create a function to update the counter with findAndModify (use $inc for self-increment during update)
- 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.