Package org.springframework.data.mongodb.core.query

Examples of org.springframework.data.mongodb.core.query.Update


    template.save(document);

    Query query = query(where("id").is(document.id));
    assumeThat(template.findOne(query, DocumentWithCollectionOfSimpleType.class).values, hasSize(1));

    Update update = new Update().push("values").each("data", "mongodb");
    template.updateMulti(query, update, DocumentWithCollectionOfSimpleType.class);

    assertThat(template.findOne(query, DocumentWithCollectionOfSimpleType.class).values, hasSize(3));
  }
View Full Code Here


    doc.string1 = Arrays.asList("spring");
    doc.string2 = Arrays.asList("one");

    template.save(doc);

    Update update = new Update().pushAll("string1", new Object[] { "data", "mongodb" });
    update.pushAll("string2", new String[] { "two", "three" });

    Query findQuery = new Query(Criteria.where("id").is(doc.id));
    template.updateFirst(findQuery, update, DocumentWithMultipleCollections.class);

    DocumentWithMultipleCollections result = template.findOne(findQuery, DocumentWithMultipleCollections.class);
View Full Code Here

        sample1, //
        sample2 //
        );
    template.save(doc);

    Update update = new Update().pull("dbRefAnnotatedList", doc.dbRefAnnotatedList.get(1));

    Query qry = query(where("id").is("1"));
    template.updateFirst(qry, update, DocumentWithDBRefCollection.class);

    DocumentWithDBRefCollection result = template.findOne(qry, DocumentWithDBRefCollection.class);
View Full Code Here

        sample1, //
        sample2 //
        );
    template.save(doc);

    Update update = new Update().pull("dbRefAnnotatedList.id", "2");

    Query qry = query(where("id").is("1"));
    template.updateFirst(qry, update, DocumentWithDBRefCollection.class);

    DocumentWithDBRefCollection result = template.findOne(qry, DocumentWithDBRefCollection.class);
View Full Code Here

    DocumentWithDBRefCollection doc = new DocumentWithDBRefCollection();
    doc.id = "1";
    doc.dbRefProperty = sample1;
    template.save(doc);

    Update update = new Update().set("dbRefProperty", sample2);

    Query qry = query(where("id").is("1"));
    template.updateFirst(qry, update, DocumentWithDBRefCollection.class);

    DocumentWithDBRefCollection updatedDoc = template.findOne(qry, DocumentWithDBRefCollection.class);
View Full Code Here

        new ModelA("data")));

    template.save(document);

    Query query = query(where("id").is(document.id).and("models._id").exists(true));
    Update update = new Update().set("models.$.value", "mongodb");
    template.findAndModify(query, update, DocumentWithCollection.class);

    DocumentWithCollection result = template.findOne(query(where("id").is(document.id)), DocumentWithCollection.class);
    assertThat(result.models.get(0).value(), is("mongodb"));
  }
View Full Code Here

    template.save(document);

    Query query = query(where("id").is(document.id));
    assumeThat(template.findOne(query, DocumentWithCollectionOfSimpleType.class).values, hasSize(1));

    Update update = new Update().addToSet("values").each("data", "mongodb");
    template.updateMulti(query, update, DocumentWithCollectionOfSimpleType.class);

    assertThat(template.findOne(query, DocumentWithCollectionOfSimpleType.class).values, hasSize(3));
  }
View Full Code Here

    CustomConversions conversions = new CustomConversions(Collections.singletonList(MyConverter.INSTANCE));
    this.converter.setCustomConversions(conversions);
    this.converter.afterPropertiesSet();

    Query query = new Query();
    Update update = new Update().set("foo", new AutogenerateableId());

    template.updateFirst(query, update, Wrapper.class);

    QueryMapper queryMapper = new QueryMapper(converter);
    DBObject reference = queryMapper.getMappedObject(update.getUpdateObject(), null);

    verify(collection, times(1)).update(Mockito.any(DBObject.class), eq(reference), anyBoolean(), anyBoolean());
  }
View Full Code Here

    v.id = 1;
    v.version = 0;

    ArgumentCaptor<DBObject> captor = ArgumentCaptor.forClass(DBObject.class);

    template.findAndModify(new Query(), new Update().set("id", "10"), VersionedEntity.class);
    verify(collection, times(1)).findAndModify(Matchers.any(DBObject.class),
        org.mockito.Matchers.isNull(DBObject.class), org.mockito.Matchers.isNull(DBObject.class), eq(false),
        captor.capture(), eq(false), eq(false));

    Assert.assertThat(captor.getValue().get("$inc"), Is.<Object> is(new BasicDBObject("version", 1L)));
View Full Code Here

    v.id = 1;
    v.version = 0;

    ArgumentCaptor<DBObject> captor = ArgumentCaptor.forClass(DBObject.class);

    template.findAndModify(new Query(), new Update().set("version", 100), VersionedEntity.class);
    verify(collection, times(1)).findAndModify(Matchers.any(DBObject.class), isNull(DBObject.class),
        isNull(DBObject.class), eq(false), captor.capture(), eq(false), eq(false));

    Assert.assertThat(captor.getValue().get("$set"), Is.<Object> is(new BasicDBObject("version", 100)));
    Assert.assertThat(captor.getValue().get("$inc"), nullValue());
View Full Code Here

TOP

Related Classes of org.springframework.data.mongodb.core.query.Update

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.