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

      maybeEmitEvent(new BeforeConvertEvent<T>(objectToSave));
      this.mongoConverter.write(objectToSave, dbObject);

      maybeEmitEvent(new BeforeSaveEvent<T>(objectToSave, dbObject));
      Update update = Update.fromDBObject(dbObject, ID_FIELD);

      doUpdate(collectionName, query, update, objectToSave.getClass(), false, false);
      maybeEmitEvent(new AfterSaveEvent<T>(objectToSave, dbObject));
    }
  }
View Full Code Here

    Person person = new Person("Oliver2");
    person.setAge(25);
    mongoTemplate.insert(person);

    Query q = new Query(Criteria.where("BOGUS").gt(22));
    Update u = new Update().set("firstName", "Sven");
    mongoTemplate.updateFirst(q, u, Person.class);
  }
View Full Code Here

    thrown.expectMessage("array");
    thrown.expectMessage("firstName");
    thrown.expectMessage("failed");

    Query query = new Query(Criteria.where("firstName").is("Amol"));
    Update upd = new Update().push("age", 29);
    template.updateFirst(query, upd, Person.class);
  }
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.