mongodb compound keys duplicate key error

950 Views Asked by At

I'm facing a duplicate key error without finding a solution. I have a compound key created using the following command:

   db.test.createIndex({"a":1,"b":1,"date":1},{unique:true})

then I inserted a document:

   {
      "a": "test_a",
      "b": "test_b",
      "date": "20170710",
      "data": "testing"
   }

and until here everything is ok. Now when I try to insert the following document:

   {
      "a": "test_a",
      "b": "test_b",
      "date": "20170711",
      "data": "testing"
   }

I get E11000 duplicate key error collection. Why this is happening if the index is different in each document? Thanks

0

There are 0 best solutions below