@Override public void updateSubscription(String checkId, Subscription subscription) { DBObject subscriptionObject = mapper.subscriptionToDBObject(subscription); DBObject subscriptionFindObject = forId(subscription.getId()); DBObject checkFindObject = forId(checkId).with("subscriptions", object("$elemMatch", subscriptionFindObject)); DBObject updateObject = object("$set", object("subscriptions.$", subscriptionObject)); getChecksCollection().update(checkFindObject, updateObject); }
@Override public Subscription createSubscription(String checkId, Subscription subscription) { subscription.setId(ObjectId.get().toString()); DBObject check = forId(checkId); DBObject query = object("$push", object("subscriptions", mapper.subscriptionToDBObject(subscription))); getChecksCollection().update(check, query); return subscription; }