I know this is an old question, but I will post my answer to posterity ...
It depends on the system you are building and on specific business rules.
I am creating moderate to large scale CRM in MongoDb, C # (Backend API) and Angular (Frontend web application) and have found that ObjectId is absolutely terrible to use in Angular Routing to select specific objects. Same thing with API controller routing.
This suggestion worked great for my project.
db.contacts.insert({ "id":db.contacts.find().Count()+1, "name":"John Doe", "emails":[ " john@doe.com ", " john.doe@business.com " ], "phone":"555111322", "status":"Active" });
The reason this is perfect for my case, but not all cases are that, as stated above, if you delete 3 entries from the collection, you will get collisions.
My business rules indicate that because of our internal SLAs, we will not be able to delete correspondence data or customer records longer than the potential duration of the application that I am writing, and therefore I simply mark the records with the listing โStatusโ, which is either โActiveโ "or" Deleted. " You can delete something from the user interface and it will say โContact deletedโ, but the whole application has changed the contact status to โDeletedโ, and when the application calls the repository for the contact list, I filter and then delete the entries before inserting data to the client application.
Therefore db.collection.find (). Count () + 1 is the perfect solution for me ...
It will not work for everyone, but if you do not delete the data, it works fine.
Alex nicholas
source share