Example usage for org.springframework.data.mongodb.core.query Update unset

List of usage examples for org.springframework.data.mongodb.core.query Update unset

Introduction

In this page you can find the example usage for org.springframework.data.mongodb.core.query Update unset.

Prototype

public Update unset(String key) 

Source Link

Document

Update using the $unset update modifier

Usage

From source file:org.ow2.play.metadata.service.MetadataServiceImpl.java

@Override
@WebMethod/*  ww  w.  ja v  a  2s.c  o  m*/
public boolean deleteMetaData(Resource resource) throws MetadataException {
    Update update = new Update();
    update.unset("metadata");
    mongoTemplate.updateFirst(
            query(where("resource.name").is(resource.getName()).and("resource.url").is(resource.getUrl())),
            update, org.ow2.play.metadata.service.document.MetaResource.class);
    return true;
}

From source file:net.cit.tetrad.resource.ManagementResource.java

private void unGroupBind(String groupBind) {
    Query q = new Query();
    q = setgroupBind(q, groupBind);/*w  w w .  j  a  v a 2s.c o  m*/
    Update update = new Update();
    update.unset("groupBind");
    monadService.updateMulti(q, update, MAV_CRITICAL, false);
}

From source file:org.slc.sli.dal.repository.MongoEntityRepository.java

@Override
protected Update getUpdateCommand(Entity entity, boolean isSuperdoc) {
    // set up update query
    Update update = new Update();

    // It is possible for the body and metaData keys to be absent in the case
    // of "orphaned" subDoc data when a document has been "hollowed out"
    Map<String, Object> entityBody = entity.getBody();
    if (entityBody != null && entityBody.size() == 0) {
        update.unset("body");
    } else {/*from w w  w  .  ja v  a  2  s . c o  m*/
        update.set("body", entityBody);
    }
    Map<String, Object> entityMetaData = entity.getMetaData();
    if (entityMetaData != null && entityMetaData.size() == 0) {
        update.unset("metaData");
    } else {
        update.set("metaData", entityMetaData);
    }

    // update should also set type in case of upsert
    String entityType = entity.getType();
    if (entityType != null && !entityType.isEmpty()) {
        update.set("type", entityType);
    }
    // superdoc need to update subdoc fields outside body
    if (isSuperdoc && entity.getEmbeddedData() != null) {
        Set<String> subdocFields = FullSuperDoc.FULL_ENTITIES.get(entity.getType());
        if (subdocFields != null) {
            for (String subdocField : subdocFields) {
                List<Entity> subdocEntities = entity.getEmbeddedData().get(subdocField);
                if (subdocEntities != null && subdocEntities.size() > 0) {
                    List<Map<String, Object>> updateEntities = new ArrayList<Map<String, Object>>();
                    for (Entity subdocEntity : subdocEntities) {
                        Map<String, Object> updateEntity = new HashMap<String, Object>();
                        updateEntity.put("_id", subdocEntity.getEntityId());
                        updateEntity.put("body", subdocEntity.getBody());
                        updateEntity.put("type", subdocEntity.getType());
                        updateEntity.put("metaData", subdocEntity.getMetaData());
                        updateEntities.add(updateEntity);
                    }
                    update.set(subdocField, updateEntities);
                } else {
                    update.unset(subdocField);
                }
            }
        }
    }
    return update;
}

From source file:piecework.repository.concrete.ProcessInstanceRepositoryCustomImpl.java

private void includeMessages(Update update, Map<String, List<Message>> messages) {
    if (messages != null) {
        if (messages.isEmpty()) {
            update.unset("messages");
        } else {//  www  .j a va2s .c  o  m
            update.set("messages", messages);
            //                MongoConverter converter = mongoOperations.getConverter();
            //                for (Map.Entry<String, List<Message>> entry : messages.entrySet()) {
            //                    String key = "messages." + entry.getKey();
            //                    List<Message> values = entry.getValue();
            //                    List<Object> dbObjects = new ArrayList<Object>();
            //
            //                    for (Message value : values) {
            //                        if (value != null) {
            //                            Object dbObject = converter.convertToMongoType(value);
            //                            dbObjects.add(dbObject);
            //                        }
            //                    }
            //
            //                    update.set(key, dbObjects);
            //                }
        }
    }
}