Example usage for org.springframework.data.mongodb.core PersonWithIdPropertyOfTypeString getId

List of usage examples for org.springframework.data.mongodb.core PersonWithIdPropertyOfTypeString getId

Introduction

In this page you can find the example usage for org.springframework.data.mongodb.core PersonWithIdPropertyOfTypeString getId.

Prototype

public String getId() 

Source Link

Usage

From source file:org.springframework.data.mongodb.core.PersonExample.java

public void doWork() {
    mongoOps.dropCollection("personexample");

    PersonWithIdPropertyOfTypeString p = new PersonWithIdPropertyOfTypeString();
    p.setFirstName("Sven");
    p.setAge(22);/*from ww  w  .j  a v  a  2  s.  c o  m*/

    mongoOps.save(p);

    PersonWithIdPropertyOfTypeString p2 = new PersonWithIdPropertyOfTypeString();
    p2.setFirstName("Jon");
    p2.setAge(23);

    mongoOps.save(p2);

    log.debug("Saved: " + p);

    p = mongoOps.findById(p.getId(), PersonWithIdPropertyOfTypeString.class);

    log.debug("Found: " + p);

    // mongoOps.updateFirst(new Query(where("firstName").is("Sven")), new Update().set("age", 24));

    // mongoOps.updateFirst(new Query(where("firstName").is("Sven")), update("age", 24));

    p = mongoOps.findById(p.getId(), PersonWithIdPropertyOfTypeString.class);
    log.debug("Updated: " + p);

    List<PersonWithIdPropertyOfTypeString> folks = mongoOps.findAll(PersonWithIdPropertyOfTypeString.class);
    log.debug("Querying for all people...");
    for (PersonWithIdPropertyOfTypeString element : folks) {
        log.debug(element);
    }

    // mongoOps.remove( query(whereId().is(p.getId())), p.getClass());

    mongoOps.remove(p);

    List<PersonWithIdPropertyOfTypeString> people = mongoOps.findAll(PersonWithIdPropertyOfTypeString.class);

    // PersonWithIdPropertyOfTypeString p2 = mongoOps.findOne(query(whereId().is(p.getId())),
    // PersonWithIdPropertyOfTypeString.class);

    log.debug("Number of people = : " + people.size());

}