I'm new to mongoDb and maybe I do not understand how it works. I created the following tables:
User:
=====
email: string;
firstName: string;
lastName: string;
password?: string;
role: string;
Role:
=====
title: string;
permissios: string;
I created 2 roles: admin and operator without problem.
But having problem to create more than 1 user.
I'm using typegoose, and I'm trying to create new user and getting duplicate key for field role.title which is in role table (but there is no dependency between the tables? role defined as string in user table).
"E11000 duplicate key error collection: db.users index: role.title_1 dup key: { : null }"
Example of code creating the user:
const user = new this.userModel({...profile});
try {
return await user.save();
} catch (e) {
the profile is: {"email":"dsd.sdsd@gmail.com","password":"123456","firstName":"Israel","lastName":"Lavi","role":"admin","_id":"5b126333e4a2c85c60592e52"}
What is wrong with my code. Thanks in advance