Problem
Using Mongoose.
- Mongo automatically creates an
_id
for each new document in a collection - I am creating a user system where i want to implement a simple, sequential
id
- Meaning the first user will be 1, the second 2, etc
- This is working OK in development, I use the
id
to work with my user data throughout the app - I set a simple variable in my
Node
application that increases by one every time a user is saved - HOWEVER, when the server re-starts, the variable resets to the original value, this is a problem
Solution?
- At this point in development it is not a big deal, but in the long term, my system is not going to hold up in production
- I am a newb but I would imagine my
Node
server will not run uninterrupted forever
Are there any easy solutions to implement what I want?
- I was thinking maybe i could save a separate document on my DB that contains my counter variable, and find it and increment it and save it again every time i save a user… this doesn’t seem like the most efficient thing in the world
- my other idea is just to use the mongo
_id
to do all my lookups - idk i find the super long strings annoying and it would be nice to just see user id’s in a simple numerical order