mongodb - MongoException: Index with name: code already exists with different options -
i have mongodb
collection term
following structure
{ "_id" : "00002c34-a4ca-42ee-b242-e9bab8e3a01f", "terminologyclass" : "user", "code" : "x67", "terminology" : "some term related notes", "notes" : "some notes" }
and java class representing term collection term.java
@document public class term{ @id protected string termid; @indexed protected string terminologyclass; @indexed(unique=true) protected string code; @indexed protected string terminology; protected string notes; //getters & setters }
i have many documents in term
collection. added new field term.java
as
@indexed protected string status;
after adding field status
term.java
, while inserting new term term
collection getting exceptoin :
com.mongodb.mongoexception: index name: code exists different options
i using mongodb version : 2.6.5 , spring-data-mongodb version : 1.3.2
you have index on collection same name, different definition. guess current code index non-unique
try: db.term.getindexes()
if indeed case (you have non-unique index on code field), issue: db.term.dropindex("code_1")
(replace code field index name).
next time boot application, it's supposed work alright.
alternatively, remove unique attribute @indexed
annotation (if don't except unique).
Comments
Post a Comment