1 00:00:02,110 --> 00:00:05,700 So how can we ensure that email is unique? 2 00:00:05,710 --> 00:00:09,440 So first of all, I'll delete that redundant entry here, 3 00:00:09,550 --> 00:00:17,080 so in my users collection I'll delete one entry and I'll identify the entry by ID by using that objectid 4 00:00:17,100 --> 00:00:19,000 here 5 00:00:19,300 --> 00:00:27,970 and now we can add a unique index. So on users, we can create that index on the email field, we pass some 6 00:00:27,970 --> 00:00:31,040 configuration here where we set unique to true 7 00:00:31,210 --> 00:00:36,030 and now we'll get an error if we try to insert something which exists already. 8 00:00:36,050 --> 00:00:38,670 So now I inserted that index 9 00:00:38,740 --> 00:00:43,230 and now let's try inserting that same email one more time. 10 00:00:46,300 --> 00:00:48,400 Now you see I get an error here 11 00:00:49,500 --> 00:00:56,740 and indeed, I print the error here on the backend server, duplicate key error collection. 12 00:00:57,050 --> 00:00:58,750 So now I get this error 13 00:00:58,790 --> 00:01:03,820 and of course you can handle it in a different way if you want but now we make sure that node duplicate 14 00:01:03,860 --> 00:01:10,730 data for the e-mail can end up. So that is another useful thing which we simply added by adding an index.