i create simple annotated java pojo , save mongodb. basically, is:
@component("vehicle") @scope("prototype") @document(collection = "vehicle") @compoundindexes({ @compoundindex(name = "platenumber_idx", def = "{ 'platenumber' : 1 }", unique = true), @compoundindex(name = "vin_idx", def = "{ 'vin' : 1 }", unique = true), @compoundindex(name = "motornumber_idx", def = "{ 'motornumber' : 1 }", unique = true) }) public class vehicle { private string platenumber; private string vin; private string motornumber; ... getters, setters, equal, hash etc. .... }
it working properly, in case need add partial index motornumber field. reason is: not necessary fill field in, therefore field can null. other hand, not allowed 2 or more similar motornumber - except, when null. can add partial index(s) vehicle collection hand, more elegant way annotations. example, here partial index:
{"motornumber" : {"$exists" : true}}
my question is: how can add option @compoundindex ? or there other options ?
Comments
Post a Comment