I'm getting this mongo duplicate key error when the following code executes. Basically, it creates a new storeAdmin document and saves it. After that, it creates a new restaurant document and assigns the previously created store admin's id to the storeAdminID field.
When the restaurant collection is empty it executes without giving an error. But when there is at least one document it gives me the above error. There is no field called current_tracking_number in any of my schemas.
// create a new store admin
const newStoreAdmin = new StoreAdmin({
...userData,
});
await newStoreAdmin.save();
// create a new restaurant for the store admin
const restaurant = new Restaurant({
storeAdminID: newStoreAdmin._id,
});
await restaurant.save();
// assign the newly created store admins id to the restaurant document
newStoreAdmin.restaurantID = restaurant._id;
await newStoreAdmin.save();