I'm using a MongoDb database and I need to make multiple fields unique. What I need is for MongoDb to check if the combination of the multiple fields are unique. Let's show an example of what I need:
If I add the following in this order in the database after adding the indexes:
{"name":"paul", "age":"21"}
{"name":"goerge", "age":"21"}
{"name":"paul", "age":"44"}
{"name":"paul", "age":"21"}
In the following example, the only one who would not be accepted would be the last one.
I've tried the following unique compound index and it doesn't work. In the preceding example, it would only keep the first one as it checks if every field is unique:
db.test.createIndex({"name":1, "age":1}, {unique:true})
I also tried, same problem:
db.test.createIndex({"name":1}, {unique:true})
db.test.createIndex({"age":1}, {unique:true})
I searched for hours and couldn't find anything that would enable me to do that.
Anyone knows a way?