我有兩個型號:的MongoDB和UPSERT問題
1 ResourceVacation:
@Id
private String resourceID;
private List<Vacation> vacationList;
2 - 休假:
@Id
private String id;
private String start;
private String title;
的JSON的ResourceVacation後,我插了進去:
{「_id」:「foo」,「_class」:「com.test.mod el.ResourceVacation」, 「vacationList」:[{ 「_id」: 「1」, 「啓動」: 「ABC」, 「標題」: 「測試」} ]}
我需要UPSERT一個假期;如果我需要的resourceId已經存在於ResourceVacation中,請將「vacationList」替換爲我擁有的json。
ELSE: 插入一個新的ResourceVacation
Vacation vacation = new Vacation("a", "a", "a");
List<Vacation> list = new ArrayList<Vacation>();
list.add(vacation);
ResourceVacation resourceVacation = new ResourceVacation("foo", list);
MongoOperations mongoOperations = mongoConfiguration.getMongoTemplate();
DBCollection db = mongoOperations.getCollection("resourceVacation");
BasicDBObject myQuery = new BasicDBObject("_id", resourceVacation.getResourceID());
BasicDBObject myUpdate = new BasicDBObject("push ", new BasicDBObject("vacationList",
resourceVacation.getVacationList()));
db.update(myQuery, myUpdate);
我得到以下異常:
java.lang.IllegalArgumentException: can't serialize class com.springway.model.Vacation
我也需要提出一個假期。 – ericsoco