Reputation: 59
Hi all I'm new to learning how to develop with Node.js using Mongoose and Express. I have been having some issues with Mongodb not correctly reflecting my schema changes.
For example, I have written a model that supposedly auto-increment _id
by 1 starting from 0 when each new document is inserted. I'm testing a few ways to do this model and so I'm constantly inserting different data.
I drop the collection each time to try to reinsert the data. However, _id
instead of starting at 0, it starts at the previous largest _id
.
This is just one of the issues that I have encountered. Some other similar Schema changes that I did on the fly also were not reflected.
I tried the following:
mongo
mongo
Is there something else that I need to shut down completely then restart before mongoose reflects the newest form of the schema? Thanks!
Upvotes: 1
Views: 1728
Reputation: 203359
To start fresh with a new schema, it's best (if possible) to drop the old database entirely (db.dropDatabase()
from the MongoDB shell), otherwise you may run into various issues (that can also be solved separately, if dropping the database isn't an option):
identitycounters
);Restarting the database server won't solve these, they do require some manual administration.
Upvotes: 1