Are you serious?
But still, do you mean code and name should be unique individually or do you mean the combination of code+name should be unique.
There is a difference, if code and name should be unique individually it means there cannot be same code in two different DB. if the combination should be unique means for one code there could be different names and vice versa.
I am going to provide a subjective answer as you haven't shown what you have tried or what you wish to try.
either you user _id as code+name making sure that it would be unique.
or you can have different key for code and name in document having a unique key indexing on both of them. or in second case having a compound unique indexing.
manpreet
Best Answer
2 years ago
In MEAN Technology,I need to develop the payroll application,In this I have two fields code and name,But code and name should be unique,how to code this in mongodb?