agave-metadata/metadata-core/src/main/java/org/iplantc/service/metadata/dao/MetadataDao.java
/**
     * Updates a single document representing a {@link MetadataItem}.
     *
     * @param doc the metadata item fields to update, marshalled to a {@link Document}.
     * @return freshly updated Document representing the metadata item
     * @throws MetadataException if unable to find Metadata item
     */
Updates a single document representing a  MetadataItem.
@param doc the metadata item fields to update, marshalled to a  Document.
@return freshly updated Document representing the metadata item
@throws MetadataException if unable to find Metadata item
Updates a single document representing a MetadataItem . @param doc the metadata item fields to update marshalled to a Document . @return freshly updated Document representing the metadata item @throws MetadataException if unable to find Metadata item
public Document updateDocument(Document doc) throws MetadataException {
        MongoCollection<MetadataItem> metadataItemMongoCollection;
        try {
            metadataItemMongoCollection = getDefaultCollection();
            doc.append("lastUpdated", new Date());
            UpdateResult update = metadataItemMongoCollection.updateOne(and(eq("uuid", doc.get("uuid")),
                    eq("tenantId", doc.get("tenantId"))), new Document("$set", doc));
            if (update.getModifiedCount() == 0) {
                throw new MetadataException("No document found with uuid " + doc.get("uuid") + ".");
            } else {
                Document uuidLookupDoc = new Document().append("uuid", doc.get("uuid")).append("tenantId", doc.get("tenantId"));
                List<Document> foundDocuments = filterFind(uuidLookupDoc, new Document());
                if (foundDocuments.size() > 0)
                    return foundDocuments.get(0);
                throw new MetadataException("No metadata item found for user with id " + doc.get("uuid"));
            }
        } catch (MongoException e) {
            throw new MetadataException("Failed to add/update metadata item.", e);
        }
    }
public Document updateDocument ( Document doc ) throws MetadataException { MongoCollection < MetadataItem > metadataItemMongoCollection ; try { metadataItemMongoCollection = getDefaultCollection ( ) ; doc . append ( "lastUpdated" , new Date ( ) ) ; UpdateResult update = metadataItemMongoCollection . updateOne ( and ( eq ( "uuid" , doc . get ( "uuid" ) ) , eq ( "tenantId" , doc . get ( "tenantId" ) ) ) , new Document ( "$set" , doc ) ) ; if ( update . getModifiedCount ( ) == 0 ) { throw new MetadataException ( "No document found with uuid " + doc . get ( "uuid" ) + "." ) ; } else { Document uuidLookupDoc = new Document ( ) . append ( "uuid" , doc . get ( "uuid" ) ) . append ( "tenantId" , doc . get ( "tenantId" ) ) ; List < Document > foundDocuments = filterFind ( uuidLookupDoc , new Document ( ) ) ; if ( foundDocuments . size ( ) > 0 ) return foundDocuments . get ( 0 ) ; throw new MetadataException ( "No metadata item found for user with id " + doc . get ( "uuid" ) ) ; } } catch ( MongoException e ) { throw new MetadataException ( "Failed to add/update metadata item." , e ) ; } }
Updates a single document representing a {@link MetadataItem}.
Updates a single document representing a { @link MetadataItem } .
//push instead of replace