Let's say I have a MongoDB Entity that looks as follows:
@Entity(value = "car")
public class Car {
public String manufacturer;
public String model;
public String year;
public Double price;
}
I would like to add an index such that the pair manufacturer,model,year
is unique.
When I try the following annotation -- @Indexes(@Index(value="manufacturer,model,year, unique=true))
-- it works. But it throws the following error:
[WARN] (main) : DatastoreImpl - This index on 'Car' is using deprecated configuration options. Please update to use the fields value on @Index: @org.mongodb.morphia.annotations.Index(unique=true, dropDups=false, background=false, name=, value=manufacturer, model, year, expireAfterSeconds=-1, disableValidation=false, sparse=false, fields=[], [email protected](unique=false, dropDups=false, background=false, name=, expireAfterSeconds=-1, disableValidation=false, language=, languageOverride=, sparse=false))
How do I configure the index properly?
Try the following annotation
@Entity(value = "car")
@Indexes(@Index(fields = { @Field("manufacturer"), @Field("model"), @Field("year") }, options = @IndexOptions(unique = true)))
public class Car {
public String manufacturer;
public String model;
public String year;
public Double price;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With