Example usage for org.springframework.data.mongodb.core MongoTemplate save

List of usage examples for org.springframework.data.mongodb.core MongoTemplate save

Introduction

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

Prototype

@Override
    public <T> T save(T objectToSave) 

Source Link

Usage

From source file:io.curly.advisor.AdvisorApplication.java

@Bean
CommandLineRunner commandLineRunner(MongoTemplate mongoTemplate) {
    return args -> {
        String s = ObjectId.get().toHexString();
        System.out.println("--------------------------------->" + s);
        Review review = new Review("foo", "55b241c6608d54d2de26b891", String.valueOf(new Random(10).nextLong()),
                "foo", new UserInfo("foo", "url"), BigDecimal.ONE);
        try {//from  ww w  . j av  a2 s  .com
            mongoTemplate.save(review);
        } catch (DuplicateKeyException e) {
            System.out.println(e);
        }
    };
}

From source file:io.curly.artifact.ArtifactoryApplication.java

@Bean
CommandLineRunner commandLineRunner(MongoTemplate mongoTemplate) {
    return args -> {
        Artifact artifact = new Artifact();
        Set<Language> languages = new HashSet<>(0);
        Set<Tag> tags = new HashSet<>(0);
        tags.add(new Tag("document"));
        tags.add(new Tag("nosql"));
        languages.add(new Language("java"));
        languages.add(new Language("groovy"));
        languages.add(new Language("ruby"));
        languages.add(new Language("scala"));
        languages.add(new Language("javascript"));
        artifact.setName("curly");
        artifact.setDescription("a hobby project");
        artifact.setAuthor("joaoevangelista");
        artifact.setCategory(new Category("database"));
        artifact.setHomePage("http://example.com");
        artifact.setIncubation(LocalDate.now().toString());
        artifact.setLanguages(languages);
        artifact.setTags(tags);/*from   ww w  . j  a  va2  s  .c  om*/
        artifact.setOwner("6969");
        mongoTemplate.save(artifact);
    };
}