Mongodb duplicate key error: How to handle the error and stop saving this record?

  mongodb, question

When there is a duplicate key value, let it not save this record again and throw it away directly. How to write an error?{
 //Don't save this. Just throw it away. How do you write this

If there is an err representative who did not write successfully, it is good to do the following directly.
The best practice is to keep at least one log here. You cannot silently swallow the errors and say nothing, which will cause great trouble to your future debugging problems.