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


Java MongoOperations类代码示例

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


MongoOperations类属于org.springframework.data.mongodb.core包,在下文中一共展示了MongoOperations类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: MongoDbGoogleAuthenticatorTokenCredentialRepository

import org.springframework.data.mongodb.core.MongoOperations; //导入依赖的package包/类
public MongoDbGoogleAuthenticatorTokenCredentialRepository(final IGoogleAuthenticator googleAuthenticator,
                                                           final MongoOperations mongoTemplate,
                                                           final String collectionName,
                                                           final boolean dropCollection) {
    this.mongoTemplate = mongoTemplate;
    this.collectionName = collectionName;
    this.googleAuthenticator = googleAuthenticator;
    Assert.notNull(this.mongoTemplate);

    if (dropCollection) {
        LOGGER.debug("Dropping database collection: [{}]", this.collectionName);
        this.mongoTemplate.dropCollection(this.collectionName);
    }

    if (!this.mongoTemplate.collectionExists(this.collectionName)) {
        LOGGER.debug("Creating database collection: [{}]", this.collectionName);
        this.mongoTemplate.createCollection(this.collectionName);
    }
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:20,代码来源:MongoDbGoogleAuthenticatorTokenCredentialRepository.java

示例7: MongoDbGoogleAuthenticatorTokenRepository

import org.springframework.data.mongodb.core.MongoOperations; //导入依赖的package包/类
public MongoDbGoogleAuthenticatorTokenRepository(final MongoOperations mongoTemplate,
                                                 final String collectionName,
                                                 final boolean dropCollection,
                                                 final long expireTokensInSeconds) {
    this.mongoTemplate = mongoTemplate;
    this.collectionName = collectionName;
    this.expireTokensInSeconds = expireTokensInSeconds;

    Assert.notNull(this.mongoTemplate);
    Assert.notNull(this.collectionName);

    if (dropCollection) {
        LOGGER.debug("Dropping database collection: [{}]", this.collectionName);
        this.mongoTemplate.dropCollection(this.collectionName);
    }

    if (!this.mongoTemplate.collectionExists(this.collectionName)) {
        LOGGER.debug("Creating database collection: [{}]", this.collectionName);
        this.mongoTemplate.createCollection(this.collectionName);
    }
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:22,代码来源:MongoDbGoogleAuthenticatorTokenRepository.java

示例8: MongoDbCasEventRepository

import org.springframework.data.mongodb.core.MongoOperations; //导入依赖的package包/类
public MongoDbCasEventRepository(final MongoOperations mongoTemplate, final String collectionName, final boolean dropCollection) {
    this.mongoTemplate = mongoTemplate;
    this.collectionName = collectionName;

    Assert.notNull(this.mongoTemplate);

    if (dropCollection) {
        LOGGER.debug("Dropping database collection: [{}]", this.collectionName);
        this.mongoTemplate.dropCollection(this.collectionName);
    }

    if (!this.mongoTemplate.collectionExists(this.collectionName)) {
        LOGGER.debug("Creating database collection: [{}]", this.collectionName);
        this.mongoTemplate.createCollection(this.collectionName);
    }
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:17,代码来源:MongoDbCasEventRepository.java

示例9: MongoServiceRegistryDao

import org.springframework.data.mongodb.core.MongoOperations; //导入依赖的package包/类
/**
 * Ctor.
 *
 * @param mongoTemplate  mongoTemplate
 * @param collectionName collectionName
 * @param dropCollection dropCollection
 */
public MongoServiceRegistryDao(final MongoOperations mongoTemplate, final String collectionName, final boolean dropCollection) {
    this.mongoTemplate = mongoTemplate;
    this.collectionName = collectionName;
    this.dropCollection = dropCollection;

    Assert.notNull(this.mongoTemplate);

    if (this.dropCollection) {
        LOGGER.debug("Dropping database collection: [{}]", this.collectionName);
        this.mongoTemplate.dropCollection(this.collectionName);
    }

    if (!this.mongoTemplate.collectionExists(this.collectionName)) {
        LOGGER.debug("Creating database collection: [{}]", this.collectionName);
        this.mongoTemplate.createCollection(this.collectionName);
    }
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:25,代码来源:MongoServiceRegistryDao.java

示例10: MongoDbMultifactorAuthenticationTrustStorage

import org.springframework.data.mongodb.core.MongoOperations; //导入依赖的package包/类
/**
 * Instantiates a new Mongo db multifactor authentication trust storage.
 *
 * @param collectionName the collection name
 * @param dropCollection id the configured collection should be dropped or recreated
 * @param mongoTemplate  the mongo template
 */
public MongoDbMultifactorAuthenticationTrustStorage(final String collectionName, final boolean dropCollection, final MongoOperations mongoTemplate) {
    this.collectionName = collectionName;
    this.mongoTemplate = mongoTemplate;

    Assert.notNull(this.mongoTemplate);

    if (dropCollection) {
        LOGGER.debug("Dropping database collection: [{}]", this.collectionName);
        this.mongoTemplate.dropCollection(this.collectionName);
    }

    if (!this.mongoTemplate.collectionExists(this.collectionName)) {
        LOGGER.debug("Creating database collection: [{}]", this.collectionName);
        this.mongoTemplate.createCollection(this.collectionName);
    }
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:24,代码来源:MongoDbMultifactorAuthenticationTrustStorage.java

示例11: onStart

import org.springframework.data.mongodb.core.MongoOperations; //导入依赖的package包/类
/**
 * Application runner to initialize a capped collection for {@link Event}s and insert a new {@link Event} every two
 * seconds.
 * 
 * @param operations
 * @param reactiveOperations
 * @return
 */
@Bean
ApplicationRunner onStart(MongoOperations operations, ReactiveMongoOperations reactiveOperations) {

	return args -> {

		CollectionOptions options = CollectionOptions.empty() //
				.capped() //
				.size(2048) //
				.maxDocuments(1000);

		operations.dropCollection(Event.class);
		operations.createCollection(Event.class, options);

		Flux.interval(Duration.ofSeconds(2)) //
				.map(counter -> new Event(LocalDateTime.now())) //
				.flatMap(reactiveOperations::save) //
				.log() //
				.subscribe();
	};
}
 
开发者ID:olivergierke,项目名称:spring-five-functional-reactive,代码行数:29,代码来源:WebfluxDemo.java

示例12: mongoSessionRepository

import org.springframework.data.mongodb.core.MongoOperations; //导入依赖的package包/类
@Bean
public MongoOperationsSessionRepository mongoSessionRepository(MongoOperations mongoOperations) {

	MongoOperationsSessionRepository repository = new MongoOperationsSessionRepository(mongoOperations);
	repository.setMaxInactiveIntervalInSeconds(this.maxInactiveIntervalInSeconds);

	if (this.mongoSessionConverter != null) {
		repository.setMongoSessionConverter(this.mongoSessionConverter);
	}

	if (StringUtils.hasText(this.collectionName)) {
		repository.setCollectionName(this.collectionName);
	}

	return repository;
}
 
开发者ID:spring-projects,项目名称:spring-session-data-mongodb,代码行数:17,代码来源:MongoHttpSessionConfiguration.java

示例13: setup

import org.springframework.data.mongodb.core.MongoOperations; //导入依赖的package包/类
/** The mongodb ops. */

	/* (non-Javadoc)
	 * @see co.aurasphere.botmill.core.datastore.adapter.DataAdapter#setup()
	 */
	public void setup() {
		
		MongoCredential credential = MongoCredential.createCredential(
				ConfigurationUtils.getEncryptedConfiguration().getProperty("mongodb.username"), 
				ConfigurationUtils.getEncryptedConfiguration().getProperty("mongodb.database"), 
				ConfigurationUtils.getEncryptedConfiguration().getProperty("mongodb.password").toCharArray());
		ServerAddress serverAddress = new ServerAddress(
				ConfigurationUtils.getEncryptedConfiguration().getProperty("mongodb.server"), 
				Integer.valueOf(ConfigurationUtils.getEncryptedConfiguration().getProperty("mongodb.port")));
		MongoClient mongoClient = new MongoClient(serverAddress, Arrays.asList(credential));
		SimpleMongoDbFactory simpleMongoDbFactory = new SimpleMongoDbFactory(mongoClient, ConfigurationUtils.getEncryptedConfiguration().getProperty("mongodb.database"));

		MongoTemplate mongoTemplate = new MongoTemplate(simpleMongoDbFactory);
		this.source = (MongoOperations) mongoTemplate;
	}
 
开发者ID:BotMill,项目名称:botmill-core,代码行数:21,代码来源:MongoDBAdapter.java

示例14: prepare

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

	Veiculo veiculo = VeiculoResourceCondition.OBJECT.get();

	MongoOperations mongoOperation = (MongoOperations) ApplicationContextProvider.getApplicationContext().getBean("mongoTemplate");

	Logradouro logradouro = new Logradouro();
	logradouro.setId("1");
	logradouro.setLogradouro("Rua das Acacias");
	logradouro.setCep("88030000");
	logradouro.setTp_logradouro("Rua");

	Infracao infracao1 = createInfracao("1", veiculo, logradouro);
	Infracao infracao2 = createInfracao("2", veiculo, logradouro);
	
	mongoOperation.save(infracao1);
	mongoOperation.save(infracao2);
}
 
开发者ID:UNGPublic,项目名称:sampleng-backend,代码行数:21,代码来源:InfracaoResourceCondition.java

示例15: unsubscribe

import org.springframework.data.mongodb.core.MongoOperations; //导入依赖的package包/类
public void unsubscribe(String subscriptionID) {
	ApplicationContext ctx = new GenericXmlApplicationContext(
			"classpath:MongoConfig.xml");
	MongoOperations mongoOperation = (MongoOperations) ctx
			.getBean("mongoTemplate");

	// Its size should be 0 or 1
	List<SubscriptionType> subscriptions = mongoOperation.find(new Query(
			Criteria.where("subscriptionID").is(subscriptionID)),
			SubscriptionType.class);

	for (int i = 0; i < subscriptions.size(); i++) {
		SubscriptionType subscription = subscriptions.get(i);
		// Remove from current Quartz
		removeScheduleFromQuartz(subscription);
		// Remove from DB list
		removeScheduleFromDB(mongoOperation, subscription);
	}
	((AbstractApplicationContext) ctx).close();
}
 
开发者ID:JaewookByun,项目名称:epcis,代码行数:21,代码来源:MysqlQueryServiceSpring.java


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