当前位置: 首页>>代码示例>>Java>>正文


Java MongoOperations.insert方法代码示例

本文整理汇总了Java中org.springframework.data.mongodb.core.MongoOperations.insert方法的典型用法代码示例。如果您正苦于以下问题:Java MongoOperations.insert方法的具体用法?Java MongoOperations.insert怎么用?Java MongoOperations.insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.data.mongodb.core.MongoOperations的用法示例。


在下文中一共展示了MongoOperations.insert方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: init

import org.springframework.data.mongodb.core.MongoOperations; //导入方法依赖的package包/类
@Bean
CommandLineRunner init(MongoOperations operations) {
	return args -> {
		// tag::log[]
		operations.dropCollection(Image.class);

		operations.insert(new Image("1",
			"learning-spring-boot-cover.jpg"));
		operations.insert(new Image("2",
			"learning-spring-boot-2nd-edition-cover.jpg"));
		operations.insert(new Image("3",
			"bazinga.png"));

		operations.findAll(Image.class).forEach(image -> {
			System.out.println(image.toString());
		});
		// end::log[]
	};
}
 
开发者ID:PacktPublishing,项目名称:Learning-Spring-Boot-2.0-Second-Edition,代码行数:20,代码来源:InitDatabase.java

示例2: init

import org.springframework.data.mongodb.core.MongoOperations; //导入方法依赖的package包/类
@Bean
CommandLineRunner init(MongoOperations operations) {
	return args -> {
		// tag::log[]
		operations.dropCollection(Image.class);

		operations.insert(new Image("1",
			"learning-spring-boot-cover.jpg", "greg"));
		operations.insert(new Image("2",
			"learning-spring-boot-2nd-edition-cover.jpg", "greg"));
		operations.insert(new Image("3",
			"bazinga.png", "phil"));

		operations.findAll(Image.class).forEach(image -> {
			System.out.println(image.toString());
		});
		// end::log[]
	};
}
 
开发者ID:PacktPublishing,项目名称:Learning-Spring-Boot-2.0-Second-Edition,代码行数:20,代码来源:InitDatabase.java

示例3: initializeUsers

import org.springframework.data.mongodb.core.MongoOperations; //导入方法依赖的package包/类
@Bean
CommandLineRunner initializeUsers(MongoOperations operations) {
	return args -> {
		operations.dropCollection(User.class);

		operations.insert(
			new User(
				null,
				"greg", "turnquist",
				new String[]{"ROLE_USER", "ROLE_ADMIN"}));
		operations.insert(
			new User(
				null,
				"phil", "webb",
				new String[]{"ROLE_USER"}));

		operations.findAll(User.class).forEach(user -> {
			System.out.println("Loaded " + user);
		});
	};
}
 
开发者ID:PacktPublishing,项目名称:Learning-Spring-Boot-2.0-Second-Edition,代码行数:22,代码来源:InitUsers.java

示例4: init

import org.springframework.data.mongodb.core.MongoOperations; //导入方法依赖的package包/类
@Bean
CommandLineRunner init(MongoOperations operations) {
	return args -> {
		// tag::log[]
		operations.dropCollection(Image.class);

		operations.insert(new Image("1",
			"learning-spring-boot-cover.jpg", "greg"));
		operations.insert(new Image("2",
			"learning-spring-boot-2nd-edition-cover.jpg", "greg"));
		operations.insert(new Image("3",
			"bazinga.png", "greg"));

		operations.findAll(Image.class).forEach(image -> {
			System.out.println(image.toString());
		});
		// end::log[]
	};
}
 
开发者ID:PacktPublishing,项目名称:Learning-Spring-Boot-2.0-Second-Edition,代码行数:20,代码来源:InitDatabase.java

示例5: init

import org.springframework.data.mongodb.core.MongoOperations; //导入方法依赖的package包/类
@Bean
CommandLineRunner init(MongoOperations operations) {
	return args -> {
		operations.dropCollection(Image.class);

		operations.insert(new Image("1",
			"learning-spring-boot-cover.jpg"));
		operations.insert(new Image("2",
			"learning-spring-boot-2nd-edition-cover.jpg"));
		operations.insert(new Image("3",
			"bazinga.png"));

		operations.findAll(Image.class).forEach(image -> {
			System.out.println(image.toString());
		});
	};
}
 
开发者ID:PacktPublishing,项目名称:Learning-Spring-Boot-2.0-Second-Edition,代码行数:18,代码来源:InitDatabase.java

示例6: main

import org.springframework.data.mongodb.core.MongoOperations; //导入方法依赖的package包/类
public static void main(String[] args) throws UnknownHostException {
    // MongoOperations mongoTemplate = new MongoTemplate(new MongoClient(), "sdcuike");
    MongoCredential mongoCredential = MongoCredential.createCredential("mongo", "sdcuike", "mongo".toCharArray());
    MongoClient mongoClient = new MongoClient(new ServerAddress("127.0.0.1", 27017), Arrays.asList(mongoCredential));

    MongoOperations mongoTemplate = new MongoTemplate(mongoClient, "sdcuike");
    mongoTemplate.insert(new Person("doctor", 1236666, UUID.randomUUID().toString()));
    List<Person> list = mongoTemplate.findAll(Person.class);

    System.out.println(list.size());
    list.forEach(System.out::println);
    // mongoTemplate.dropCollection(Person.class);

}
 
开发者ID:sdcuike,项目名称:book-reading,代码行数:15,代码来源:MongoApp.java

示例7: prepare

import org.springframework.data.mongodb.core.MongoOperations; //导入方法依赖的package包/类
@Override
public void prepare(Description description) {
    MongoOperations mongoOperation = (MongoOperations) ApplicationContextProvider.getApplicationContext().getBean("mongoTemplate");

    Veiculo veiculo = createVeiculo();
    Condutor proprietario = veiculo.getProprietario();

    mongoOperation.insert(proprietario);
    mongoOperation.insert(veiculo);
    
    OBJECT.set(veiculo);
}
 
开发者ID:UNGPublic,项目名称:sampleng-backend,代码行数:13,代码来源:VeiculoResourceCondition.java

示例8: insert

import org.springframework.data.mongodb.core.MongoOperations; //导入方法依赖的package包/类
/**
 * テストデータをMongoDBに登録します。
 * @param operations {@link MongoOperations}
 * @param executables 登録するJSONデータ
 * @param config {@link MongoInitialize}
 */
protected void insert(MongoOperations operations, Object executables, MongoInitialize config) {
    L.info(Strings.substitute(R.getString("I-MONGO-TEST#0003"), Maps.hash("value", executables.toString())));
    if (executables.getClass().isArray()) {
        List<Object> gen = Lists.gen((Object[])executables);
        operations.insert(gen, findCollectionName(config));
    } else {
        operations.insert(executables, findCollectionName(config));
    }
}
 
开发者ID:ctc-g,项目名称:sinavi-jfw,代码行数:16,代码来源:TestMongoKeeper.java

示例9: prepare

import org.springframework.data.mongodb.core.MongoOperations; //导入方法依赖的package包/类
@Override
public void prepare(Description description) {
	MongoOperations mongoOperation = Application.getMongoOperations();

	Condutor proprietario = createProprietario();

	mongoOperation.insert(proprietario);
	
	OBJECT.set(proprietario);

}
 
开发者ID:UNGPublic,项目名称:sampleng-backend,代码行数:12,代码来源:CondutorResourceCondition.java


注:本文中的org.springframework.data.mongodb.core.MongoOperations.insert方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。