spring-data-mongodb

spring data mongodb mapping dynamic field

拜拜、爱过 提交于 2019-12-06 13:57:31
问题 I've this model in my java class @Document public class Template { private String type; private String code; @Version Long version; } I need to add a new field, named template , and map this field as dynamic in other words I would model a document like this { _id: 'id' type:'myType', code:'myCode' template:{ someFiled:[ { subField1:'value1', subField2:'value2' }, { sub1Field1:'1value1', sub1Field2:'1value2' } ....................... ], otherField:[ { otherField1:'value1', otherField2:'value2'

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

放肆的年华 提交于 2019-12-06 13:54:52
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 constructor. If I add the new property to the constructor, then the application can no longer read the

Spring Data query over two documents

南楼画角 提交于 2019-12-06 12:43:36
问题 I have an m:n connection in my MongoDB, MessageUserConnection is the class between User and Message. Now I will get all MessageUserConnections where MessageUserConnection#confirmationNeeded is true, read is false and Message#receiveDate is not older than the last week. Is there any possibility to do this with Spring Data? Thanks a lot! public class MessageUserConnection { @Id private String id; @DBRef private User userCreatedMessage; @DBRef private Message message; private Boolean

How to set Mongodb Field Naming Strategy in Spring boot

为君一笑 提交于 2019-12-06 06:09:19
I am using spring boot 1.3.1.Release with Spring Data Mongodb and want to setup field naming strategy for fields. Below is my application.properties file: spring.data.mongodb.uri=mongodb://localhost/test spring.data.mongodb.field-naming-strategy=org.springframework.data.mongodb.core.mapping.SnakeCaseFieldNamingStrategy spring.data.mongodb.repositories.enabled=true spring.data.mongodb.database=test Everything is working fine except the field naming strategy. Any help will be highly appreciated. SpringBoot 1.3 has spring-data-mongodb version 1.8 and in this version of jar class with name

Build dynamic queries with Spring Data MongoDB Criteria

旧巷老猫 提交于 2019-12-06 06:03:30
问题 I would like to run a bulk delete operation on a list of documents in MongoDB that have been selected by the user in the UI so I need to dynamically build a query that looks like the following (the or clause expands for every document selected): { $and: [ { "contentType": "application/vnd.sometype" }, { $or: [ { "metadata.name": "someName", "metadata.version": "someVersion" }, { "metadata.name": "someOtherName", "metadata.version": "someOtherVersion" } ] } ] }, Fields: null, Sort: null Just

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

不羁的心 提交于 2019-12-06 05:53:41
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 the case you'll see a 409 Conflict. I am currently using this way for PUT, and a 409 conflict is what I

How to properly load and configure Spring beans from an external utility jar

大兔子大兔子 提交于 2019-12-06 04:15:57
问题 Currently I have a utility jar that contains a number of datastore services. Behind the scenes these datastore services use Spring Data MongoDB, and everything is configured using an app-context.xml file in the utility jar. I want this utility jar to be able to change the backing store without having to change anything that uses this utility jar. Now, I want to create a spring mvc web application that uses the datastore services from this utility jar. How do I set this up so that the spring

Prevent Spring Data for Mongo to convert ids to ObjectId

旧城冷巷雨未停 提交于 2019-12-06 03:58:36
问题 I'm using Spring Data for Mongo on an existing database. The previous application used plain strings for ids instead of ObjectId. My problem is that Spring Data insists on converting the strings to ObjectId, which makes all queries by id to fail. For example, when I do repository.findOne('') , the query executed is { "_id" : { "$oid" : "50cf9f34458cf91108ceb2b4"}} when it should be { "_id" : "50cf9f34458cf91108ceb2b4" } Is there a way to avoid Spring Data to convert string ids to ObjectId?

Spring data mongodb, how to set SSL?

為{幸葍}努か 提交于 2019-12-06 02:09:19
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, database, password.toCharArray())}); return mongo; } @Bean public MongoTemplate mongoTemplate(Mongo mongo)

how to use $lookup stage in java with spring data mongodb? [duplicate]

家住魔仙堡 提交于 2019-12-05 19:42:52
This question already has an answer here : lookup in mongodb aggregation (1 answer) Closed last year . Up to last version of spring i have seen lot of stack over flow questions which shows there is no support for this operation in spring-data-mongodb is there any support for this operation in new spring-data-mongodb 1.10.0 db.orders.aggregate([ { $lookup: { from: "inventory", localField: "item", foreignField: "sku", as: "inventory_docs" } } ]) Lookup support has been there since 1.9 version. LookupOperation lookupOperation = LookupOperation.newLookup(). from("inventory"). localField("item").