spring-data-mongodb

MongoException: Index with name: code already exists with different options

风流意气都作罢 提交于 2019-12-08 16:13:28
问题 I have a mongodb collection term with following structure { "_id" : "00002c34-a4ca-42ee-b242-e9bab8e3a01f", "terminologyClass" : "USER", "code" : "X67", "terminology" : "some term related notes", "notes" : "some notes" } and a java class representing the term collection as Term.java @Document public class Term{ @Id protected String termId; @Indexed protected String terminologyClass; @Indexed(unique=true) protected String code; @Indexed protected String terminology; protected String notes; /

Invalid parameter index! You seem to have declare too little query method parameters! - Spring Mongo TextSearch

依然范特西╮ 提交于 2019-12-08 12:48:07
问题 I am developing Spring + Mongo Data JPA example for Text Search. When I am trying to search using OrderID 102. I was expecting all records to be fetch from DB those record contains 102 in OrderID . Please help me I see following error is coming. org.springframework.data.repository.query.ParameterOutOfBoundsException: Invalid parameter index! You seem to have declare too little query method parameters! at org.springframework.data.repository.query.Parameters.getParameter(Parameters.java:178) at

Caused by: org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class com.example.Hobbies

天涯浪子 提交于 2019-12-08 10:03:00
问题 How to insert the embedded documents using BSONObject ? When I am trying to insert the embedded document, getting error shown below. I wanted to save null values for the Date and firstName for example. I tried some options using Spring Data Mongo, but it doesn't work out well. I am getting below error: java.lang.IllegalStateException: Failed to execute CommandLineRunner at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:816) [spring-boot-2.1.4.RELEASE.jar:2.1.4

spring mvc @Autowired error Unsatisfied 'required' dependency of type

旧城冷巷雨未停 提交于 2019-12-08 09:56:53
问题 I have user service that treat user entity, and @Autowired in user controller class before use user service. so, I got the error: Unsatisfied 'required' dependency of type [class com.yes.service.UserService]. Expected at least 1 matching bean here the codes: userService package com.yes.service; import java.util.List; import java.util.UUID; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.yes.domain.User; import com.yes

How to retrieve all matching elements present inside array in Mongo DB?

痞子三分冷 提交于 2019-12-08 06:39:59
问题 I have document shown below: { name: "testing", place:"London", documents: [ { x:1, y:2, }, { x:1, y:3, }, { x:4, y:3, } ] } I want to retrieve all matching documents i.e. I want o/p in below format: { name: "testing", place:"London", documents: [ { x:1, y:2, }, { x:1, y:3, } ] } What I have tried is : db.test.find({"documents.x": 1},{_id: 0, documents: {$elemMatch: {x: 1}}}); But, it gives first entry only. 回答1: As JohnnyHK said, the answer in MongoDB: select matched elements of

how to use sum and condition in group using spring data mongodb aggregation

亡梦爱人 提交于 2019-12-08 05:02:33
问题 db.test.aggregate( [ { $group: { _id: "$id", "total":{$sum: 1}, "live" : { $sum : {$cond : { if: { $eq: ["$status",A"]},then: 1, else: 0}}}, "chat_hrs" :{ $avg: { $subtract: [ "$end_time", "$start_time" ] } }}}]). Kindly help me to write springmvc coding to use mongodb aggregation for the above query. 回答1: You can use the below aggregation pipeline. import static org.springframework.data.mongodb.core.aggregation.Aggregation.*; import static org.springframework.data.mongodb.core.aggregation

Spring Boot 2.1 duplicate reactiveMongoTemplate bean

爱⌒轻易说出口 提交于 2019-12-08 02:22:14
问题 I have the following Spring Boot @Configuration class: @Configuration @EnableReactiveMongoRepositories class MongoConfiguration : AbstractReactiveMongoConfiguration() { override fun reactiveMongoClient() = MongoClients.create() override fun getDatabaseName() = "mydb" override fun customConversions(): MongoCustomConversions = MongoCustomConversions(listOf(ZonedDateTimeReadConverter(), ZonedDateTimeWriteConverter())) } The application fails to start, and logs this message: The bean

E11000 duplicate key error when doing PUT for modifiable resource with Spring Data Rest

痴心易碎 提交于 2019-12-08 01:20:18
问题 Update: According to this question, the author of Spring data rest say, the @Version properties will become ETags in response header. And there are two options for update: Just PUT without an If-Match header -- enforces overriding whatever is present on the server as the aggregate gets loaded, incoming data mapped onto it and it written back. You still get optimistic locking applied if another client changed the aggregate in the meantime (although an admittedly very short window). If that's

How to add a final field to an existing spring-data-mongodb document collection?

倖福魔咒の 提交于 2019-12-07 22:26:12
问题 I have an existing document collection using spring-data-mongodb version 1.0.2.RELEASE . @Document public class Snapshot { @Id private final long id; private final String description; private final boolean active; @PersistenceConstructor public Snapshot(long id, String description, boolean active) { this.id = id; this.description = description; this.active = active; } } I'm trying to add a new property private final boolean billable; . Since the properties are final they need to be set in the

Spring data mongodb, how to set SSL?

ε祈祈猫儿з 提交于 2019-12-07 15:58:55
问题 I have so far failed to find a good explanation/doc on the topic. I am using <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-mongodb</artifactId> <version>1.9.5.RELEASE</version> </dependency> and my code looks like this: @Bean public MongoClientFactoryBean mongo() { MongoClientFactoryBean mongo = new MongoClientFactoryBean(); mongo.setHost(host); mongo.setPort(port); mongo.setCredentials(new MongoCredential[]{MongoCredential.createCredential(username,