I have a Schema.User and a Schema.Pattern which is a one-to-many relationship. I decided to split instead of embed because of the way the data is going to be queried. Also, patterns are going to have handful of projects as a one-to-many as well.
At this point I’m just playing around with the concept of one-to-many. I have an express app and a controller that CRUDs the User collect without problem. My problem is when I create the first pattern. I have the following route for creating patterns.
Well its obvious that the model doesn’t have email field but for some reason the collection does have a unique index created on that field name. If you have this index then the database will assume a null value form a non existing email field document and that cannot be duplicated…
I suspect at at some moment you might accidentally created it , just run
The index, if any, should be in the user collection since that’s the collection that has the email.unique: true. I don’t have a pattern.email property at all and I never ran any mongo command to create indexes.
@Jay – I want a user to have many patterns. @Pavel_Duchovny – indeed the patterns collections has the index. I’m not sure how that got there since I never got the email property in the patterns collection.
I had to drop the database and run the REST endpoint through postman again and that solved the issue. Now the patterns collection doesn’t have that index. Somehow that index got there.