The best way I found to make this to my purpose was to increment from the max value you have in the field and for that, I used the following syntax:
var array = db.CollectionName.find({}).sort({ _id: -1 }).limit(1).toArray(); var max = max.length?max[0]+1:1;
Even if an User ID is deleted, this wont create duplicate